-
Notifications
You must be signed in to change notification settings - Fork 9
130 lines (114 loc) · 7.22 KB
/
auto-git-release-production.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Summary:
# Automatically tag and release when changes land on the "main" branch.
# It uses "semantic-version" to resolve the next version to use, and then we use GitHub CLI to create or update the releases.
#
# See https://github.com/PaulHatch/semantic-version https://github.com/PaulHatch/semantic-version/tree/v5.0.2
# See https://github.com/softprops/action-gh-release https://github.com/softprops/action-gh-release/tree/v1
name: 'Auto release'
on:
push:
branches:
- main
jobs:
tag-and-release:
runs-on: ubuntu-latest
steps:
- name: Fetching all commits for the current branch
uses: actions/checkout@v3
with:
fetch-depth: 0 # Force fetch all commits - See https://github.com/PaulHatch/semantic-version#important-note-regarding-the-checkout-action
- run: "echo \"GITHUB_SHA: ${{ github.sha }}\""
# Outputs documentation: https://github.com/PaulHatch/semantic-version/blob/master/src/main.ts#L22-L33
- name: Resolving next Release Candidate version using semantic-version
uses: paulhatch/[email protected]
id: next_semantic_version
with: # See https://github.com/PaulHatch/semantic-version#usage
tag_prefix: "v" # The prefix to use to identify tags
major_pattern: "(MAJOR)" # A string which, if present in a git commit, indicates that a change represents a major (breaking) change
minor_pattern: "(MINOR)" # Same as above except indicating a minor change
version_format: "${major}.${minor}.${patch}-rc.${increment}" # A string to determine the format of the version output
bump_each_commit: true # If this input is set to true, every commit will be treated as a new version, bumping the patch, minor, or major version based on the commit message.
- name: Printing semantic-version outputs (for debugging)
run: |
echo "Most useful outputs:"
echo "Next version: ${{steps.next_semantic_version.outputs.version}}"
echo "Next version tag: ${{steps.next_semantic_version.outputs.version_tag}}"
echo -e "\n All outputs:"
echo "version: ${{steps.next_semantic_version.outputs.version}}"
echo "major: ${{steps.next_semantic_version.outputs.major}}"
echo "minor: ${{steps.next_semantic_version.outputs.minor}}"
echo "patch: ${{steps.next_semantic_version.outputs.patch}}"
echo "increment: ${{steps.next_semantic_version.outputs.increment}}"
echo "version_type: ${{steps.next_semantic_version.outputs.version_type}}"
echo "changed: ${{steps.next_semantic_version.outputs.changed}}"
echo "authors: ${{steps.next_semantic_version.outputs.authors}}"
echo "version_tag: ${{steps.next_semantic_version.outputs.version_tag}}"
echo "previous_commit: ${{steps.next_semantic_version.outputs.previous_commit}}"
echo "current_commit: ${{steps.next_semantic_version.outputs.current_commit}}"
- name: Creating Git release tag for the "${{steps.next_semantic_version.outputs.version_tag}}" version
run: |
gh release create ${{steps.next_semantic_version.outputs.version_tag}} \
--title "${{steps.next_semantic_version.outputs.version_tag}}" \
--latest \
--generate-notes \
--target "${{github.sha}}"
env:
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
# Check if the major version already exists (if it doesn't, we'll create it - if it does, we'll update it)
- name: Check if tag "v${{steps.next_semantic_version.outputs.major}}" exists
uses: mukunku/[email protected]
id: majorTagExists
with: # See https://github.com/mukunku/tag-exists-action#inputs
tag: "v${{steps.next_semantic_version.outputs.major}}"
- run: "echo \"Check if majorTagExists: ${{ steps.majorTagExists.outputs.exists }}\""
# See https://cli.github.com/manual/gh_release_create
- name: Creating new release for the major "v${{steps.next_semantic_version.outputs.major}}" version
if: ${{ steps.majorTagExists.outputs.exists == 'false' }}
run: |
gh release create v${{steps.next_semantic_version.outputs.major}} \
--title "v${{steps.next_semantic_version.outputs.major}} MAJOR release (auto-updated)" \
--generate-notes \
--target "${{github.sha}}"
env:
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
# See https://cli.github.com/manual/gh_release_edit
- name: Recreating existing release for the major "v${{steps.next_semantic_version.outputs.major}}" version
if: ${{ steps.majorTagExists.outputs.exists == 'true' }}
run: |
# Delete and create the release again
gh release delete v${{steps.next_semantic_version.outputs.major}} --cleanup-tag --yes
gh release create v${{steps.next_semantic_version.outputs.major}} \
--title "v${{steps.next_semantic_version.outputs.major}} MAJOR release (auto-updated)" \
--generate-notes \
--target "${{github.sha}}"
env:
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
# Check if the minor version already exists (if it doesn't, we'll create it - if it does, we'll update it)
- name: Check if tag "v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}}" exists
uses: mukunku/[email protected]
id: minorTagExists
with: # See https://github.com/mukunku/tag-exists-action#inputs
tag: "v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}}"
- run: "echo \"Check if minorTagExists: ${{ steps.minorTagExists.outputs.exists }}\""
# See https://cli.github.com/manual/gh_release_create
- name: Creating new release for the minor "v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}}" version
if: ${{ steps.minorTagExists.outputs.exists == 'false' }}
run: |
gh release create v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}} \
--title "v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}} MINOR release (auto-updated)" \
--generate-notes \
--target "${{github.sha}}"
env:
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
# See https://cli.github.com/manual/gh_release_edit
- name: Recreating existing release for the minor "v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}}" version
if: ${{ steps.minorTagExists.outputs.exists == 'true' }}
run: |
# Delete and create the release again
gh release delete v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}} --cleanup-tag --yes
gh release create v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}} \
--title "v${{steps.next_semantic_version.outputs.major}}.${{steps.next_semantic_version.outputs.minor}} MINOR release (auto-updated)" \
--generate-notes \
--target "${{github.sha}}"
env:
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"