-
-
Notifications
You must be signed in to change notification settings - Fork 11
141 lines (121 loc) · 4.74 KB
/
sync-release-version.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
131
132
133
134
135
136
137
138
139
140
141
name: Update release version.
on:
release:
types: [published]
jobs:
check-version:
runs-on: ubuntu-latest
name: semver-diff
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v8
- name: Run semver-diff
id: semver-diff
uses: tj-actions/semver-diff@v3
- name: Show release type
if: steps.semver-diff.outputs.release_type == 'major'
run: |
OLD_VERSION=$(echo "${{ steps.semver-diff.outputs.old_version }}" | cut -d'.' -f1 | cut -d'v' -f2)
MAJOR_VERSION=$(echo "${{ steps.semver-diff.outputs.new_version }}" | cut -d'.' -f1 | cut -d'v' -f2)
make upgrade-from-one-version-to-a-major-version OLD_VERSION=$OLD_VERSION MAJOR_VERSION=$MAJOR_VERSION
- name: Commit the change to the main branch and update the latest version
if: steps.semver-diff.outputs.release_type == 'major'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git tag -d ${{ steps.branch-name.outputs.tag }}
git add .
git commit -m "chore: upgraded from ${{ steps.semver-diff.outputs.old_version }} -> ${{ steps.semver-diff.outputs.new_version }}"
git push -f origin main
git tag ${{ steps.branch-name.outputs.tag }}
git push -f origin ${{ steps.branch-name.outputs.tag }}
release:
name: release
runs-on: ubuntu-latest
needs: check-version
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
update-version:
runs-on: ubuntu-latest
needs: release
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main
- name: Sync release version.
uses: tj-actions/sync-release-version@v13
id: sync-release-version
with:
pattern: '${{ github.repository }}@'
only_major: true
paths: |
README.md
- name: Sync release version for action.yml.
uses: tj-actions/sync-release-version@v13
id: sync-release-version-action
with:
pattern: 'version: '
paths: |
action.yml
- name: Run git-cliff
uses: tj-actions/git-cliff@v1
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v8
- name: Verify Changed files
uses: tj-actions/verify-changed-files@v20
id: verify-changed-files
with:
files: |
README.md
HISTORY.md
action.yml
- name: Commit changes
if: steps.verify-changed-files.outputs.files_changed == 'true'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git tag -d ${{ steps.branch-name.outputs.tag }}
git add ${{ steps.verify-changed-files.outputs.changed_files }}
git commit -m "chore: upgraded from ${{ steps.sync-release-version.outputs.old_version }} -> ${{ steps.sync-release-version.outputs.new_version }}"
git tag ${{ steps.branch-name.outputs.tag }}
git push -f origin ${{ steps.branch-name.outputs.tag }}
- name: Run release-tagger
uses: tj-actions/release-tagger@v4
with:
token: ${{ secrets.PAT_TOKEN }}
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6.0.5
with:
base: "main"
labels: "merge when passing"
title: "Upgraded to ${{ steps.sync-release-version.outputs.new_version }}"
branch: "upgrade-to-${{ steps.sync-release-version.outputs.new_version }}"
commit-message: "Upgraded from ${{ steps.sync-release-version.outputs.old_version }} -> ${{ steps.sync-release-version.outputs.new_version }}"
body: "View [CHANGES](https://github.com/${{ github.repository }}/compare/${{ steps.sync-release-version.outputs.old_version }}...${{ steps.sync-release-version.outputs.new_version }})"
token: ${{ secrets.PAT_TOKEN }}