-
Notifications
You must be signed in to change notification settings - Fork 8
72 lines (66 loc) · 2.52 KB
/
release.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
name: Weekly Release
on:
workflow_dispatch:
schedule:
# At 00:00 on Monday
- cron: "0 0 * * 1"
jobs:
bump-version-and-release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: main
fetch-depth: 0 # Fetch all history for all branches and tags
# Requires "Read and Write access to code" permission
token: ${{ secrets.RELEASE_ACTION_ACCESS_TOKEN }}
- name: Check for changes since last tag
id: check_changes
run: |
LATEST_TAG=$(git tag --merged=main --sort=-committerdate | head -n 1)
CHANGES=$(git log $LATEST_TAG..HEAD --oneline)
if [[ -z "$CHANGES" ]]; then
echo "No changes since the last tag."
else
echo "Changes detected since the last tag."
echo "has_changes=true" >> $GITHUB_OUTPUT
fi
- name: Create Tag
if: ${{ steps.check_changes.outputs.has_changes }}
id: tag_version
run: |
# Extracts the latest version tag, bumps the minor version
LATEST_VERSION=$(git tag --sort=-authordate --merged=main | head --lines 1)
if ! [[ "$LATEST_VERSION" =~ ^v[0-9]+\.[0-9]+\..* ]]; then
echo "Invalid tag format, cannot bump version of: $LATEST_VERSION"
exit 1
fi
MAJOR=$(echo $LATEST_VERSION | cut -d. -f1)
MINOR=$(echo $LATEST_VERSION | cut -d. -f2)
NEW_MINOR=$((MINOR+1))
NEW_TAG="${MAJOR}.${NEW_MINOR}.0"
echo ::set-output name=tag::$NEW_TAG
git tag $NEW_TAG
git push origin --tags
- name: "Create release"
if: ${{ steps.check_changes.outputs.has_changes }}
uses: "actions/github-script@v6"
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
script: |
try {
const response = await github.rest.repos.createRelease({
draft: false,
generate_release_notes: true,
name: "Weekly Release ${{ steps.tag_version.outputs.tag }}",
owner: context.repo.owner,
prerelease: false,
repo: context.repo.repo,
tag_name: "${{ steps.tag_version.outputs.tag }}",
});
core.exportVariable('RELEASE_ID', response.data.id);
core.exportVariable('RELEASE_UPLOAD_URL', response.data.upload_url);
} catch (error) {
core.setFailed(error.message);
}