-
Notifications
You must be signed in to change notification settings - Fork 2
113 lines (97 loc) · 3.7 KB
/
prerelease.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
name: prerelease
on:
# Run Every Wednesday at 01:00 AM UTC
# schedule:
# - cron: '0 2 * * 3'
workflow_dispatch:
inputs:
release-tag:
description: "Release tag (default: Patch)"
required: true
type: choice
default: 'patch'
options:
- patch
- minor
- major
skip-release:
description: "Skip the tag creation step (default: false)"
type: boolean
default: false
permissions: write-all
jobs:
prerelease:
name: Prerelease
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.RELEASE_TOKEN }}
- name: Setup Go
uses: actions/setup-go@v5
with:
cache: true
go-version-file: 'go.mod'
cache-dependency-path: go.sum
- name: Configure Git
env:
TOKEN: ${{ secrets.RELEASE_TOKEN }}
run: |
git config --global advice.detachedHead false
git config --global url."https://${TOKEN}:[email protected]/".insteadOf "https://github.com/"
git config user.name "sylviamoss"
git config user.email "[email protected]"
- name: Check For Changes
id: changes
run: |
CURRENT_VERSION=$(git describe --tags `git rev-list --tags --max-count=1`)
DIFF_CONTENT=$(git diff $CURRENT_VERSION origin/master)
if [[ $DIFF_CONTENT == "" ]]; then
echo "There were no changes since the last release."
echo "There were no changes since the last release." >> $GITHUB_STEP_SUMMARY
echo "HAS_CHANGES=false" >> $GITHUB_OUTPUT
else
echo "There were changes since the last release."
echo "HAS_CHANGES=true" >> $GITHUB_OUTPUT
echo "CURRENT_VERSION=$CURRENT_VERSION" >> "$GITHUB_ENV"
fi
- name: Prepare Release
if: steps.changes.outputs.HAS_CHANGES == 'true'
env:
RELEASE_TAG: ${{ inputs.release-tag }}
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
run: |
CURRENT_VERSION_PARTS=(${CURRENT_VERSION//./ })
MAJOR=${CURRENT_VERSION_PARTS[0]}
MINOR=${CURRENT_VERSION_PARTS[1]}
PATCH=${CURRENT_VERSION_PARTS[2]}
if [[ $RELEASE_TAG == "major" ]]; then
MAJOR=$((MAJOR+1))
MINOR=0
PATCH=0
elif [[ $RELEASE_TAG == "minor" ]]; then
MINOR=$((MINOR+1))
PATCH=0
elif [[ $RELEASE_TAG == "patch" ]]; then
PATCH=$((PATCH+1))
fi
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
echo "NEW_VERSION=$NEW_VERSION" >> "$GITHUB_ENV"
echo "Current Version is: $CURRENT_VERSION"
echo "New Version will be: $NEW_VERSION"
echo "## Updating ${CURRENT_VERSION} to ${NEW_VERSION}" >> $GITHUB_STEP_SUMMARY
echo "## Commits that will be added to the release" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
git log --oneline $CURRENT_VERSION...master | cat >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
- name: Release New Version
if: ${{ success() && github.ref_name == 'master' && steps.changes.outputs.HAS_CHANGES == 'true' && !inputs.skip-release }}
env:
# Github actions need special tokens to be able to trigger other workflows
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
run: |
git tag -a ${NEW_VERSION} -m "New version ${NEW_VERSION}"
echo "Pushing new tag to remote, which will trigger the Release workflow"
git push --tags