Skip to content

Commit bb86ad4

Browse files
committed
ci: generate supergraph version with release-please
1 parent 6c4bc5f commit bb86ad4

File tree

3 files changed

+64
-16
lines changed

3 files changed

+64
-16
lines changed

.github/workflows/_supergraph_publish.yaml

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

18+
- name: Setup Node
19+
uses: actions/[email protected]
20+
21+
- name: Install release-please & simple-git
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 supergraph_tag = require('.github/workflows/supergraph_tag.js');
31+
const token = "${{ github.token }}";
32+
return await supergraph_tag({github, context, token})
33+
1834
- name: Setup Helm
35+
if: steps.version.outputs.result != ''
1936
uses: azure/[email protected]
2037

2138
- name: Download Schema Artifact
39+
if: steps.version.outputs.result != ''
2240
uses: actions/[email protected]
2341
with:
2442
name: supergraph.graphql
2543
path: charts/supergraph
2644

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-
4045
- name: Package Chart
41-
run: helm package charts/supergraph --version "${{ steps.version.outputs.version }}"
46+
if: steps.version.outputs.result != ''
47+
run: helm package charts/supergraph --version ${{ steps.version.outputs.result }}
4248

4349
- name: Generate Image Name
50+
if: steps.version.outputs.result != ''
4451
run: |
4552
IMAGE_REPOSITORY="oci://ghcr.io/$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]' | tr '[_]' '[\-]')"
4653
echo "Using Image Name: $IMAGE_REPOSITORY"
4754
echo "IMAGE_REPOSITORY=$IMAGE_REPOSITORY" >> $GITHUB_ENV
4855
4956
- name: Log in to GitHub Docker Registry
50-
if: github.event_name == 'push' && ( startsWith(github.ref, 'refs/tags') || startsWith(github.ref, 'refs/heads/main') )
57+
if: steps.version.outputs.result != '' && github.event_name == 'push' && ( startsWith(github.ref, 'refs/tags') || startsWith(github.ref, 'refs/heads/main') )
5158
uses: docker/[email protected]
5259
with:
5360
registry: ghcr.io
5461
username: ${{ github.actor }}
5562
password: ${{ secrets.GITHUB_TOKEN }}
5663

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

.github/workflows/ci.yaml

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

.github/workflows/supergraph_tag.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const releasePlease = require('release-please');
2+
const simpleGit = require('simple-git');
3+
4+
module.exports = async ({github, context, token}) => {
5+
const ghRelease = await releasePlease.GitHub.create({
6+
owner: context.repo.owner,
7+
repo: context.repo.repo,
8+
token: token,
9+
});
10+
11+
const manifest = await releasePlease.Manifest.fromManifest(
12+
ghRelease,
13+
ghRelease.repository.defaultBranch,
14+
'release-please-config.json',
15+
'.release-please-manifest.json',
16+
{}
17+
);
18+
19+
const pullRequests = await manifest.buildPullRequests();
20+
const pullRequest = pullRequests.find((pullRequest) => pullRequest.updates.some((update) => update.path === 'charts/supergraph/Chart.yaml'));
21+
console.log(`Supergraph Pull Request: ${JSON.stringify(pullRequest)}`);
22+
23+
const git = simpleGit();
24+
const lastTag = await git.raw('describe', '--tags', '--match', 'supergraph@v*', 'HEAD').catch((err) => undefined);
25+
console.log(`Last Tag: ${JSON.stringify(lastTag)}`);
26+
const commitsSince = lastTag ? await git.raw('rev-list', `${lastTag}..HEAD`, '--count') : await git.raw('rev-list', '--count', '--all');
27+
console.log(`Commits Since: ${commitsSince}`);
28+
29+
let rcVersion = '';
30+
if (pullRequest !== undefined) {
31+
32+
const releaseData = pullRequest.body.releaseData.find((release) => release.component === 'supergraph-schema');
33+
rcVersion = commitsSince !== 0 ? `${releaseData.version.major}.${releaseData.version.minor}.${releaseData.version.patch}-rc${commitsSince}` : `${releaseData.version.major}.${releaseData.version.minor}.${releaseData.version.patch}`;
34+
console.log(`Release Candidate Version: ${rcVersion}`);
35+
} else if (lastTag !== undefined && commitsSince === 0) {
36+
rcVersion = lastTag.split("@v").pop();
37+
};
38+
39+
return rcVersion
40+
}

0 commit comments

Comments
 (0)