Skip to content

Commit 6874dba

Browse files
authored
Use gh CLI for creating and updating GH releases (#50)
1 parent 2a6b973 commit 6874dba

File tree

3 files changed

+147
-46
lines changed

3 files changed

+147
-46
lines changed

.github/workflows/auto-git-release-production.yml

Lines changed: 70 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Summary:
22
# Automatically tag and release when changes land on the "main" branch.
3+
# It uses "semantic-version" to resolve the next version to use, and then we use GitHub CLI to create or update the releases.
34
#
45
# See https://github.com/PaulHatch/semantic-version https://github.com/PaulHatch/semantic-version/tree/v5.0.2
56
# See https://github.com/softprops/action-gh-release https://github.com/softprops/action-gh-release/tree/v1
@@ -50,28 +51,74 @@ jobs:
5051
echo "current_commit: ${{steps.next_semantic_version.outputs.current_commit}}"
5152
5253
- name: Creating Git release tag for the "${{steps.next_semantic_version.outputs.version_tag}}" version
53-
uses: ncipollo/release-action@v1
54-
with: # See https://github.com/softprops/action-gh-release#-customizing
55-
token: "${{ secrets.GITHUB_TOKEN }}"
56-
tag: ${{steps.next_semantic_version.outputs.version_tag}}
57-
name: "Automatic release ${{steps.next_semantic_version.outputs.version_tag}}"
58-
makeLatest: true
59-
allowUpdates: false
60-
prerelease: false
61-
generateReleaseNotes: true
62-
artifacts: |
63-
CHANGELOG.md
54+
run: |
55+
gh release create v${{steps.next_semantic_version.outputs.version_tag}} \
56+
--title "v${{steps.next_semantic_version.outputs.version_tag}}" \
57+
--generate-notes \
58+
--target $GITHUB_SHA
59+
env:
60+
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
6461

65-
- name: Updating Git release tag for the major "v${{steps.next_semantic_version.outputs.major}}" version
66-
uses: ncipollo/release-action@v1
67-
with: # See https://github.com/softprops/action-gh-release#-customizing
68-
token: "${{ secrets.GITHUB_TOKEN }}"
62+
# Check if the major version already exists (if it doesn't, we'll create it - if it does, we'll update it)
63+
- name: Check if tag "v${{steps.next_semantic_version.outputs.major}}" exists
64+
uses: mukunku/[email protected]
65+
id: majorTagExists
66+
with: # See https://github.com/mukunku/tag-exists-action#inputs
6967
tag: "v${{steps.next_semantic_version.outputs.major}}"
70-
name: "v${{steps.next_semantic_version.outputs.major}} latest release (auto-update)"
71-
allowUpdates: true
72-
removeArtifacts: true
73-
replacesArtifacts: true
74-
prerelease: false
75-
generateReleaseNotes: true
76-
artifacts: |
77-
CHANGELOG.md
68+
69+
- run: "echo \"Check if majorTagExists: ${{ steps.majorTagExists.outputs.exists }}\""
70+
71+
# See https://cli.github.com/manual/gh_release_create
72+
- name: Creating new release for the major "v${{steps.next_semantic_version.outputs.major}}" version
73+
if: ${{ steps.majorTagExists.outputs.exists == 'false' }}
74+
run: |
75+
gh release create v${{steps.next_semantic_version.outputs.major}} \
76+
--title "v${{steps.next_semantic_version.outputs.major}} MAJOR release (auto-updated)" \
77+
--latest \
78+
--generate-notes \
79+
--target $GITHUB_SHA
80+
env:
81+
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
82+
83+
# See https://cli.github.com/manual/gh_release_edit
84+
- name: Updating existing release for the major "v${{steps.next_semantic_version.outputs.major}}" version
85+
if: ${{ steps.majorTagExists.outputs.exists == 'true' }}
86+
run: |
87+
gh release edit v${{steps.next_semantic_version.outputs.major}} \
88+
--title "v${{steps.next_semantic_version.outputs.major}} MAJOR release (auto-updated)" \
89+
--latest \
90+
--target $GITHUB_SHA
91+
env:
92+
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
93+
94+
# Check if the minor version already exists (if it doesn't, we'll create it - if it does, we'll update it)
95+
- name: Check if tag "v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}}" exists
96+
uses: mukunku/[email protected]
97+
id: minorTagExists
98+
with: # See https://github.com/mukunku/tag-exists-action#inputs
99+
tag: "v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}}"
100+
101+
- run: "echo \"Check if minorTagExists: ${{ steps.minorTagExists.outputs.exists }}\""
102+
103+
# See https://cli.github.com/manual/gh_release_create
104+
- name: Creating new release for the minor "v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}}" version
105+
if: ${{ steps.minorTagExists.outputs.exists == 'false' }}
106+
run: |
107+
gh release create v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}} \
108+
--title "v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}} MINOR release (auto-updated)" \
109+
--generate-notes \
110+
--latest \
111+
--target $GITHUB_SHA
112+
env:
113+
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
114+
115+
# See https://cli.github.com/manual/gh_release_edit
116+
- name: Updating existing release for the minor "v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}}" version
117+
if: ${{ steps.minorTagExists.outputs.exists == 'true' }}
118+
run: |
119+
gh release edit v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}} \
120+
--title "v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}} MINOR release (auto-updated)" \
121+
--latest \
122+
--target $GITHUB_SHA
123+
env:
124+
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

.github/workflows/auto-git-release-staging.yml

Lines changed: 71 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Summary:
22
# Automatically tag and release when changes land on the "main" branch.
3+
# It uses "semantic-version" to resolve the next version to use, and then we use GitHub CLI to create or update the releases.
34
#
45
# See https://github.com/PaulHatch/semantic-version https://github.com/PaulHatch/semantic-version/tree/v5.0.2
56
# See https://github.com/softprops/action-gh-release https://github.com/softprops/action-gh-release/tree/v1
@@ -48,25 +49,75 @@ jobs:
4849
echo "current_commit: ${{steps.next_semantic_version.outputs.current_commit}}"
4950
5051
- name: Creating Git release tag for the "v${{steps.next_semantic_version.outputs.version}}" version
51-
uses: ncipollo/release-action@v1
52-
with: # See https://github.com/softprops/action-gh-release#-customizing
53-
token: "${{ secrets.GITHUB_TOKEN }}"
54-
tag: "v${{steps.next_semantic_version.outputs.version}}"
55-
name: "Automatic release v${{steps.next_semantic_version.outputs.version}}"
56-
allowUpdates: false
57-
prerelease: true
58-
generateReleaseNotes: true
59-
artifacts: |
60-
CHANGELOG.md
52+
run: |
53+
gh release create v${{steps.next_semantic_version.outputs.version}} \
54+
--title "v${{steps.next_semantic_version.outputs.version}}" \
55+
--generate-notes \
56+
--prerelease \
57+
--target $GITHUB_SHA
58+
env:
59+
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
6160

62-
- name: Updating Git release tag for the major "v${{steps.next_semantic_version.outputs.major}}-rc" version
63-
uses: ncipollo/release-action@v1
64-
with: # See https://github.com/softprops/action-gh-release#-customizing
65-
token: "${{ secrets.GITHUB_TOKEN }}"
61+
# Check if the major version already exists (if it doesn't, we'll create it - if it does, we'll update it)
62+
- name: Check if tag "v${{steps.next_semantic_version.outputs.major}}-rc" exists
63+
uses: mukunku/[email protected]
64+
id: majorTagExists
65+
with: # See https://github.com/mukunku/tag-exists-action#inputs
6666
tag: "v${{steps.next_semantic_version.outputs.major}}-rc"
67-
name: "v${{steps.next_semantic_version.outputs.major}}-rc latest release (auto-update)"
68-
allowUpdates: true
69-
prerelease: true
70-
generateReleaseNotes: true
71-
artifacts: |
72-
CHANGELOG.md
67+
68+
- run: "echo \"Check if majorTagExists: ${{ steps.majorTagExists.outputs.exists }}\""
69+
70+
# See https://cli.github.com/manual/gh_release_create
71+
- name: Creating new release for the major "v${{steps.next_semantic_version.outputs.major}}-rc" version
72+
if: ${{ steps.majorTagExists.outputs.exists == 'false' }}
73+
run: |
74+
gh release create v${{steps.next_semantic_version.outputs.major}}-rc \
75+
--title "v${{steps.next_semantic_version.outputs.major}}-rc MAJOR release (auto-updated)" \
76+
--generate-notes \
77+
--prerelease \
78+
--target $GITHUB_SHA
79+
env:
80+
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
81+
82+
# See https://cli.github.com/manual/gh_release_edit
83+
- name: Updating existing release for the major "v${{steps.next_semantic_version.outputs.major}}-rc" version
84+
if: ${{ steps.majorTagExists.outputs.exists == 'true' }}
85+
run: |
86+
gh release edit v${{steps.next_semantic_version.outputs.major}}-rc \
87+
--title "v${{steps.next_semantic_version.outputs.major}}-rc MAJOR release (auto-updated)" \
88+
--prerelease \
89+
--target $GITHUB_SHA
90+
env:
91+
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
92+
93+
# Check if the minor version already exists (if it doesn't, we'll create it - if it does, we'll update it)
94+
- name: Check if tag "v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}}-rc" exists
95+
uses: mukunku/[email protected]
96+
id: minorTagExists
97+
with: # See https://github.com/mukunku/tag-exists-action#inputs
98+
tag: "v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}}-rc"
99+
100+
- run: "echo \"Check if minorTagExists: ${{ steps.minorTagExists.outputs.exists }}\""
101+
102+
# See https://cli.github.com/manual/gh_release_create
103+
- name: Creating new release for the minor "v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}}-rc" version
104+
if: ${{ steps.minorTagExists.outputs.exists == 'false' }}
105+
run: |
106+
gh release create v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}}-rc \
107+
--title "v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}}-rc MINOR release (auto-updated)" \
108+
--generate-notes \
109+
--prerelease \
110+
--target $GITHUB_SHA
111+
env:
112+
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
113+
114+
# See https://cli.github.com/manual/gh_release_edit
115+
- name: Updating existing release for the minor "v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}}-rc" version
116+
if: ${{ steps.minorTagExists.outputs.exists == 'true' }}
117+
run: |
118+
gh release edit v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}}-rc \
119+
--title "v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}}-rc MINOR release (auto-updated)" \
120+
--prerelease \
121+
--target $GITHUB_SHA
122+
env:
123+
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ While those options can be useful, we intend to give some "production-grade" bes
246246

247247
- **Do NOT use `@latest` for production**, ever. While only "supposed-to-be-stable" versions will be tagged
248248
as `@latest`, it could harbor bugs nonetheless.
249-
- You can use auto-upgrading major version, such as `@v1`, but this is not a best practice, see our explanations below.
249+
- You can use auto-upgrading major version, such as `@v1` or `@v1.2`, but this is not always the best practice, see our explanations below.
250250

251-
### Special tags and production-grade apps best practices
251+
### Special tags and best practices for production-grade apps
252252

253253
Here are a few useful options you can use to pin a more-or-less specific version of our GitHub Action, alongside some "
254254
production-grade" best practices.
@@ -260,6 +260,9 @@ production-grade" best practices.
260260
- `@{MAJOR}`, e.g: `@v1`, can be used on production, but we do not advise to do so (SAFE-ISH)
261261
- `@{MAJOR}-rc`, e.g: `@v1-rc`, **reserved for development mode**, useful when debugging on a specific prerelease
262262
version (UNSAFE)
263+
- `@{MAJOR}.{MINOR}`, e.g: `@v1.2`, can be used on production, but we do not advise to do so (SAFE-ISH)
264+
- `@{MAJOR}.{MINOR}-rc`, e.g: `@v1.2-rc`, **reserved for development mode**, useful when debugging on a specific prerelease
265+
version (UNSAFE)
263266
- `@latest`, **reserved for development mode**, useful when debugging (UNSAFE)
264267

265268
**"But, what is the issue with the `@{MAJOR}-{MINOR}-{PATCH}` way to pin a specific version"?**
@@ -271,7 +274,7 @@ That's why **pinning a specific commit SHA is the only truly safe option**. This
271274
changed against your will**.
272275

273276
Most people won't care about this and will use a MAJOR version tag instead anyway, such as `@v1`. It's common, but not
274-
the best practice.
277+
often the best practice.
275278

276279
It all comes down to the risks you're ready to take, and it's up to you to decide what's best in your situation.
277280

0 commit comments

Comments
 (0)