-
Notifications
You must be signed in to change notification settings - Fork 4
145 lines (138 loc) Β· 5.36 KB
/
release.yaml
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
142
143
144
145
# Automatically release a new version when a PR is merged to branch `release`
name: "release"
on:
workflow_run:
workflows: [ 'ci' ]
types: [ 'completed' ]
branches: [ 'main', 'release', 'dev' ]
env:
BRANCH_TO_RELEASE: 'release'
TAG_PREFIX: 'v'
jobs:
ReleaseDryRun:
runs-on: ubuntu-latest
outputs:
RESULT: ${{ steps.release_dry_run.outputs.result }}
VERSION: ${{ steps.release_dry_run.outputs.releaseVersion }}
RELEASE_NOTES: ${{ steps.release_dry_run.outputs.releaseNotes }}
steps:
- name: Dummy 1
run: |
echo "BRANCH_TO_RELEASE: ${BRANCH_TO_RELEASE}"
echo "GITHUB_REF: ${GITHUB_REF}"
echo "TAG_PREFIX: ${TAG_PREFIX}"
echo "github.event.workflow_run.event: ${{ github.event.workflow_run.event }}"
echo "github.event.workflow_run.conclusion: ${{ github.event.workflow_run.conclusion }}"
echo "github.event.pull_request: ${{ github.event.pull_request }}"
- name: Dummy 2
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
console.log(context.payload.workflow_run)
if (context.payload.workflow_run.event == 'pull_request') {
console.log(context.payload.pull_request)
}
- name: Check out code
uses: actions/checkout@v4
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
- name: Release (dry-run)
id: release_dry_run
uses: btnguyen2k/action-semrelease@v3
with:
dry-run: true
auto-mode: true
github-token: ${{ secrets.GITHUB_TOKEN }}
tag-major-release: false
tag-minor-release: false
branches: ${{ env.BRANCH_TO_RELEASE }}
tag-prefix: ${{ env.TAG_PREFIX }}
tag-only: true
Release:
runs-on: ubuntu-latest
if: |
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success' &&
github.event.pull_request.merged == true
needs: [ 'ReleaseDryRun' ]
permissions:
contents: write # to be able to publish a GitHub release
outputs:
RESULT: ${{ needs.ReleaseDryRun.outputs.RESULT }}
VERSION: ${{ needs.ReleaseDryRun.outputs.VERSION }}
RELEASE_NOTES: ${{ needs.ReleaseDryRun.outputs.RELEASE_NOTES }}
steps:
- name: Update module meta
run: |
RESULT='${{ needs.ReleaseDryRun.outputs.RESULT }}'
VERSION='${{ needs.ReleaseDryRun.outputs.VERSION }}'
RELEASE_NOTES='${{ needs.ReleaseDryRun.outputs.RELEASE_NOTES }}'
echo "π Updating module meta..."
echo " - RESULT: ${RESULT}"
echo " - VERSION: ${VERSION}"
echo " - RELEASE_NOTES: ${RELEASE_NOTES}"
if [ "${RESULT}" == "SUCCESS" ]; then
echo "β
Done."
else
echo "β SKIPPED."
fi
# if [ "${RESULT}" == "SUCCESS" ]; then
# DATE=`date +%Y-%m-%d`
# FILE_CHANGELOG="RELEASE-NOTES.md"
# FILE_MODULE="module.go"
# head -1 ${FILE_CHANGELOG} > .temp.md
# echo -e "\n## ${DATE} - v${VERSION}\n\n${RELEASE_NOTES}" >> .temp.md
# tail -n +2 ${FILE_CHANGELOG} >> .temp.md
# mv -f .temp.md ${FILE_CHANGELOG}
# echo ========== content of ${FILE_CHANGELOG} ==========
# cat ${FILE_CHANGELOG}
#
# sed -i -E "s/^(\s*Version\s*=\s*)\"[^\"]+\"/\1\"${VERSION}\"/" ${FILE_MODULE}
# echo ========== content of ${FILE_MODULE} ==========
# cat ${FILE_MODULE}
#
# echo ========== update .go files ==========
# sed -i -E "s/<<VERSION>>/v${VERSION}/" ./*.go
#
# echo ========== commit updates ==========
# git config --global user.email "<>"
# git config --global user.name "CI Build"
# git commit -am "Update ${FILE_CHANGELOG} and ${FILE_MODULE} for new version ${VERSION}"
# git push origin ${BRANCH_TO_RELEASE}
#
# echo ========== tag ==========
# git tag -f -a "${TAG_PREFIX}${VERSION}" -m "Release ${TAG_PREFIX}/v${VERSION}"
# git push origin "${TAG_PREFIX}${VERSION}" -f
# echo "β
Done."
# else
# echo "β SKIPPED."
# fi
# MergeToMaster:
# runs-on: ubuntu-latest
# needs: [ 'Release' ]
# permissions:
# pull-requests: write # to be able to create PRs or comment on released PRs
# steps:
# - uses: actions/github-script@v7
# env:
# RESULT: ${{ needs.Release.outputs.RESULT }}
# RELEASE_NOTES: ${{ needs.Release.outputs.RELEASE_NOTES }}
# with:
# script: |
# if (process.env['RESULT'] != 'SUCCESS') {
# console.log('β SKIPPED.');
# return;
# }
# const {data: pr} = await github.rest.pulls.create({
# owner: context.repo.owner,
# repo: context.repo.repo,
# title: "Merge branch semver to master after releasing new version ${{ needs.Release.outputs.VERSION }}",
# body: process['env']['RELEASE_NOTES'],
# head: process['env']['BRANCH_TO_RELEASE'],
# base: 'master',
# maintainer_can_modify: true,
# });
# console.log('β
Created PR: ', pr);