Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup release-please #65

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/_release_please.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Release Please

on:
workflow_call:
outputs:
apps-chart-released:
value: ${{ jobs.release_please.apps-chart-released }}
graph-chart-released:
value: ${{ jobs.release_please.graph-chart-released }}
monitoring-chart-released:
value: ${{ jobs.release_please.monitoring-chart-released }}
supergraph-chart-released:
value: ${{ jobs.release_please.supergraph-chart-released }}

jobs:
release_please:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
id-token: write
steps:
- name: Checkout source
uses: actions/[email protected]
with:
fetch-depth: 0

- name: Release Please
id: release
uses: googleapis/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
config-file: release-please-config.json
manifest-file: .release-please-manifest.json
fork: false
67 changes: 51 additions & 16 deletions .github/workflows/_supergraph_publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,80 @@ jobs:
with:
fetch-depth: 0

- name: Setup Node
uses: actions/[email protected]

- name: Install release-please
run: npm install release-please simple-git

- name: Generate Chart Version
id: version
uses: actions/[email protected]
with:
result-encoding: string
script: |
const releasePlease = require('release-please');
const simpleGit = require('simple-git');

const ghRelease = await releasePlease.GitHub.create({
owner: context.repo.owner,
repo: context.repo.repo,
token: '${{ github.token }}'
});

const manifest = await releasePlease.Manifest.fromManifest(
ghRelease,
ghRelease.repository.defaultBranch,
'release-please-config.json',
'.release-please-manifest.json',
{}
);

const pullRequests = await manifest.buildPullRequests();
const pullRequest = pullRequests.find((pullRequest) => pullRequest.updates.some((update) => update.path === 'charts/supergraph/Chart.yaml'));
console.log(`Supergraph Pull Request: ${JSON.stringify(pullRequest)}`);

const git = simpleGit();
const lastTag = await git.raw('describe', '--tags', '--match', 'supergraph@v*', 'HEAD').catch((err) => undefined);
console.log(`Last Tag: ${JSON.stringify(lastTag)}`);
const commitsSince = lastTag ? await git.raw('rev-list', `${lastTag}..HEAD`, '--count') : await git.raw('rev-list', '--count', '--all');
console.log(`Commits Since: ${commitsSince}`);

const releaseData = pullRequest.body.releaseData.find((release) => release.component === 'supergraph-schema');
const rcVersion = pullRequest ? `${releaseData.version.major}.${releaseData.version.minor}.${releaseData.version.patch}-rc${commitsSince}` : '';
console.log(`Release Candidate Version: ${rcVersion}`);
return rcVersion

- name: Setup Helm
if: steps.version.outputs.result != ''
uses: azure/[email protected]

- name: Download Schema Artifact
if: steps.version.outputs.result != ''
uses: actions/[email protected]
with:
name: supergraph.graphql
path: charts/supergraph

- name: Generate Chart Version
id: version
run: |
if LATEST_TAG=$(git describe --tags --abbrev=0); then
COMMITS_SINCE=$(git rev-list $LATEST_TAG..HEAD --count)
else
LATEST_TAG="0.0.0"
COMMITS_SINCE=$(git rev-list HEAD --count)
fi
VERSION=$([ "$COMMITS_SINCE" == 0 ] && echo "$LATEST_TAG" || echo "$LATEST_TAG+$COMMITS_SINCE" )
echo "Using Version: $VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT

- name: Package Chart
run: helm package charts/supergraph --version "${{ steps.version.outputs.version }}"
if: steps.version.outputs.result != ''
run: helm package charts/supergraph --version ${{ steps.version.outputs.result }}

- name: Generate Image Name
if: steps.version.outputs.result != ''
run: |
IMAGE_REPOSITORY="oci://ghcr.io/$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]' | tr '[_]' '[\-]')"
echo "Using Image Name: $IMAGE_REPOSITORY"
echo "IMAGE_REPOSITORY=$IMAGE_REPOSITORY" >> $GITHUB_ENV

- name: Log in to GitHub Docker Registry
if: github.event_name == 'push' && ( startsWith(github.ref, 'refs/tags') || startsWith(github.ref, 'refs/heads/main') )
if: steps.version.outputs.result != '' && github.event_name == 'push' && ( startsWith(github.ref, 'refs/tags') || startsWith(github.ref, 'refs/heads/main') )
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Publish Chart
if: github.event_name == 'push' && ( startsWith(github.ref, 'refs/tags') || startsWith(github.ref, 'refs/heads/main') )
if: steps.version.outputs.result != '' && github.event_name == 'push' && ( startsWith(github.ref, 'refs/tags') || startsWith(github.ref, 'refs/heads/main') )
run: helm push $(ls supergraph-*.tgz) ${{ env.IMAGE_REPOSITORY }}
9 changes: 9 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ jobs:
# Deduplicate jobs from pull requests and branch pushes within the same repo.
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
uses: ./.github/workflows/_lint_commits.yaml

release_please:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: ./.github/workflows/_release_please.yaml
permissions:
contents: write
pull-requests: write
id-token: write

helm_lint:
# Deduplicate jobs from pull requests and branch pushes within the same repo.
Expand All @@ -24,6 +32,7 @@ jobs:
# Deduplicate jobs from pull requests and branch pushes within the same repo.
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
needs:
- release_please
- helm_lint
- supergraph_generate
uses: ./.github/workflows/_supergraph_publish.yaml
Expand Down
1 change: 1 addition & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
53 changes: 53 additions & 0 deletions release-please-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
"bootstrap-sha": "ee1cb51e2177608be9e291f6bde17ca5d867016e",
"include-component-in-tag": true,
"include-v-in-tag": true,
"tag-separator": "@",
"separate-pull-requests": true,
"bump-minor-pre-major": true,
"bump-patch-for-minor-pre-major": true,
"packages": {
"charts/apps": {
"release-type": "helm",
"release-as": "0.2.2"
},
"charts/graph": {
"release-type": "helm",
"release-as": "0.11.1"
},
"charts/monitoring": {
"release-type": "helm",
"release-as": "0.2.0"
},
"charts/supergraph": {
"release-type": "helm",
"component": "supergraph"
},
"schema": {
"package-name": "supergraph-schema",
"release-type": "simple",
"component": "supergraph-schema"
},
"workflows/compose": {
"package-name": "compose",
"release-type": "simple",
"release-as": "0.1.0"
},
"workflows/update": {
"package-name": "update",
"release-type": "simple",
"release-as": "0.1.0"
}
},
"plugins": [
{
"type": "linked-versions",
"groupName": "supergraph",
"components": [
"supergraph",
"supergraph-schema"
]
}
]
}
Loading