Skip to content

Commit 6a1c027

Browse files
committed
ci: generate supergraph version with release-please
1 parent 8bea442 commit 6a1c027

File tree

2 files changed

+52
-16
lines changed

2 files changed

+52
-16
lines changed

.github/workflows/_supergraph_publish.yaml

+51-16
Original file line numberDiff line numberDiff line change
@@ -15,45 +15,80 @@ jobs:
1515
with:
1616
fetch-depth: 0
1717

18+
- name: Setup Node
19+
uses: actions/[email protected]
20+
21+
- name: Install release-please
22+
run: npm install release-please simple-git
23+
24+
- name: Generate Chart Version
25+
id: version
26+
uses: actions/[email protected]
27+
with:
28+
result-encoding: string
29+
script: |
30+
const releasePlease = require('release-please');
31+
const simpleGit = require('simple-git');
32+
33+
const ghRelease = await releasePlease.GitHub.create({
34+
owner: context.repo.owner,
35+
repo: context.repo.repo,
36+
token: '${{ github.token }}'
37+
});
38+
39+
const manifest = await releasePlease.Manifest.fromManifest(
40+
ghRelease,
41+
ghRelease.repository.defaultBranch,
42+
'release-please-config.json',
43+
'.release-please-manifest.json',
44+
{}
45+
);
46+
47+
const pullRequests = await manifest.buildPullRequests();
48+
const pullRequest = pullRequests.find((pullRequest) => pullRequest.updates.some((update) => update.path === 'charts/supergraph/Chart.yaml'));
49+
console.log(`Supergraph Pull Request: ${JSON.stringify(pullRequest)}`);
50+
51+
const git = simpleGit();
52+
const lastTag = await git.raw('describe', '--tags', '--match', 'supergraph@v*', 'HEAD').catch((err) => undefined);
53+
console.log(`Last Tag: ${JSON.stringify(lastTag)}`);
54+
const commitsSince = lastTag ? await git.raw('rev-list', `${lastTag}..HEAD`, '--count') : await git.raw('rev-list', '--count', '--all');
55+
console.log(`Commits Since: ${commitsSince}`);
56+
57+
const releaseData = pullRequest.body.releaseData.find((release) => release.component === 'supergraph-schema');
58+
const rcVersion = pullRequest ? `${releaseData.version.major}.${releaseData.version.minor}.${releaseData.version.patch}-rc${commitsSince}` : '';
59+
console.log(`Release Candidate Version: ${rcVersion}`);
60+
return rcVersion
61+
1862
- name: Setup Helm
63+
if: steps.version.outputs.result != ''
1964
uses: azure/[email protected]
2065

2166
- name: Download Schema Artifact
67+
if: steps.version.outputs.result != ''
2268
uses: actions/[email protected]
2369
with:
2470
name: supergraph.graphql
2571
path: charts/supergraph
2672

27-
- name: Generate Chart Version
28-
id: version
29-
run: |
30-
if LATEST_TAG=$(git describe --tags --abbrev=0); then
31-
COMMITS_SINCE=$(git rev-list $LATEST_TAG..HEAD --count)
32-
else
33-
LATEST_TAG="0.0.0"
34-
COMMITS_SINCE=$(git rev-list HEAD --count)
35-
fi
36-
VERSION=$([ "$COMMITS_SINCE" == 0 ] && echo "$LATEST_TAG" || echo "$LATEST_TAG+$COMMITS_SINCE" )
37-
echo "Using Version: $VERSION"
38-
echo "version=$VERSION" >> $GITHUB_OUTPUT
39-
4073
- name: Package Chart
41-
run: helm package charts/supergraph --version "${{ steps.version.outputs.version }}"
74+
if: steps.version.outputs.result != ''
75+
run: helm package charts/supergraph --version ${{ steps.version.outputs.result }}
4276

4377
- name: Generate Image Name
78+
if: steps.version.outputs.result != ''
4479
run: |
4580
IMAGE_REPOSITORY="oci://ghcr.io/$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]' | tr '[_]' '[\-]')"
4681
echo "Using Image Name: $IMAGE_REPOSITORY"
4782
echo "IMAGE_REPOSITORY=$IMAGE_REPOSITORY" >> $GITHUB_ENV
4883
4984
- name: Log in to GitHub Docker Registry
50-
if: github.event_name == 'push' && ( startsWith(github.ref, 'refs/tags') || startsWith(github.ref, 'refs/heads/main') )
85+
if: steps.version.outputs.result != '' && github.event_name == 'push' && ( startsWith(github.ref, 'refs/tags') || startsWith(github.ref, 'refs/heads/main') )
5186
uses: docker/[email protected]
5287
with:
5388
registry: ghcr.io
5489
username: ${{ github.actor }}
5590
password: ${{ secrets.GITHUB_TOKEN }}
5691

5792
- name: Publish Chart
58-
if: github.event_name == 'push' && ( startsWith(github.ref, 'refs/tags') || startsWith(github.ref, 'refs/heads/main') )
93+
if: steps.version.outputs.result != '' && github.event_name == 'push' && ( startsWith(github.ref, 'refs/tags') || startsWith(github.ref, 'refs/heads/main') )
5994
run: helm push $(ls supergraph-*.tgz) ${{ env.IMAGE_REPOSITORY }}

.github/workflows/ci.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
# Deduplicate jobs from pull requests and branch pushes within the same repo.
3333
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
3434
needs:
35+
- release_please
3536
- helm_lint
3637
- supergraph_generate
3738
uses: ./.github/workflows/_supergraph_publish.yaml

0 commit comments

Comments
 (0)