@@ -15,45 +15,80 @@ jobs:
15
15
with :
16
16
fetch-depth : 0
17
17
18
+ - name : Setup Node
19
+
20
+
21
+ - name : Install release-please
22
+ run : npm install release-please simple-git
23
+
24
+ - name : Generate Chart Version
25
+ id : version
26
+
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
+
18
62
- name : Setup Helm
63
+ if : steps.version.outputs.result != ''
19
64
20
65
21
66
- name : Download Schema Artifact
67
+ if : steps.version.outputs.result != ''
22
68
23
69
with :
24
70
name : supergraph.graphql
25
71
path : charts/supergraph
26
72
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
-
40
73
- 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 }}
42
76
43
77
- name : Generate Image Name
78
+ if : steps.version.outputs.result != ''
44
79
run : |
45
80
IMAGE_REPOSITORY="oci://ghcr.io/$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]' | tr '[_]' '[\-]')"
46
81
echo "Using Image Name: $IMAGE_REPOSITORY"
47
82
echo "IMAGE_REPOSITORY=$IMAGE_REPOSITORY" >> $GITHUB_ENV
48
83
49
84
- 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') )
51
86
52
87
with :
53
88
registry : ghcr.io
54
89
username : ${{ github.actor }}
55
90
password : ${{ secrets.GITHUB_TOKEN }}
56
91
57
92
- 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') )
59
94
run : helm push $(ls supergraph-*.tgz) ${{ env.IMAGE_REPOSITORY }}
0 commit comments