-
Notifications
You must be signed in to change notification settings - Fork 0
166 lines (150 loc) · 5.83 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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# https://github.com/azu/monorepo-github-releases/blob/main/.github/workflows/release.yml
# This workflow often runs following steps when a PR is merged to main branch.
# 1. jobs.check checks if we need to release
# 2. jobs.release publish packages
#
# Note: Force publish
# You can publish packages manually by running workflow dispatch
# This workflow dispatch skip jobs.check process
# 1. dispatch "release" workflow
# 2. Open Release Page
# 3. Generate Release Note
name: Release
on:
pull_request:
branches:
- main
types: [ closed ]
workflow_dispatch: # force release
jobs:
check:
permissions:
contents: read
runs-on: ubuntu-latest
# when release PR is merged or workflow_dispatch is triggered, run this job
if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
outputs:
EXISTS_TAG: ${{ steps.tag_check.outputs.EXISTS_TAG }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set PACKAGE_VERSION
run: echo "PACKAGE_VERSION=$(cat lerna.json | jq -r .version)" >> $GITHUB_ENV
- name: Tag Check
id: tag_check
run: |
GET_API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/git/ref/tags/${TAG_NAME}"
http_status_code=$(curl -LI $GET_API_URL -o /dev/null -w '%{http_code}\n' -s \
-H "Authorization: token ${GITHUB_TOKEN}")
if [ "$http_status_code" -ne "404" ] ; then
echo "EXISTS_TAG=true" >> $GITHUB_OUTPUT
else
echo "EXISTS_TAG=false" >> $GITHUB_OUTPUT
fi
env:
TAG_NAME: v${{ env.PACKAGE_VERSION }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
release:
runs-on: ubuntu-latest
needs: check
if: always() && (needs.check.outputs.EXISTS_TAG == 'false')
permissions:
contents: write
issues: write
pull-requests: write
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Detect package manager
id: detect-package-manager
run: |
if [ -f "${{ github.workspace }}/yarn.lock" ]; then
echo "manager=yarn" >> $GITHUB_OUTPUT
echo "command=install" >> $GITHUB_OUTPUT
echo "runner=yarn" >> $GITHUB_OUTPUT
exit 0
elif [ -f "${{ github.workspace }}/package.json" ]; then
echo "manager=npm" >> $GITHUB_OUTPUT
echo "command=ci" >> $GITHUB_OUTPUT
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
exit 0
else
echo "Unable to determine package manager"
exit 1
fi
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: latest
cache: ${{ steps.detect-package-manager.outputs.manager }}
cache-dependency-path: ./package-lock.json
# registry-url: 'https://npm.pkg.github.com' # [EXAMPLE]
# for publishing packages to npm
registry-url: https://registry.npmjs.org
- name: Git Identity
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/$GITHUB_REPOSITORY
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set PACKAGE_VERSION
run: echo "PACKAGE_VERSION=$(cat lerna.json | jq -r .version)" >> $GITHUB_ENV
- name: Install dependencies
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
- name: Publish
run: ${{ steps.detect-package-manager.outputs.manager }} run ci:release
env:
# actions/setup-node create .npmrc with `NODE_AUTH_TOKEN` env if `registry-url` is defined
# === `echo "${ registry-url }/:_authToken=${ NODE_AUTH_TOKEN }" > .npmrc`
# NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # [EXAMPLE]
# for publishing packages to npm
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Git Tag
uses: pkgdeps/git-tag-action@v2
with:
version: ${{ env.PACKAGE_VERSION }}
github_token: ${{ secrets.GITHUB_TOKEN }}
github_repo: ${{ github.repository }}
git_commit_sha: ${{ github.sha }}
git_tag_prefix: "v"
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.PACKAGE_VERSION }}
# Copy Pull Request's tile and body to Release Note
name: ${{ github.event.pull_request.title }}
body: ${{ github.event.pull_request.body }}
draft: false
prerelease: false
generate_release_notes: ${{ !github.event.pull_request.body }}
- uses: actions/github-script@v6
if: github.event_name != 'workflow_dispatch'
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '🎉 Release https://github.com/${{ github.repository }}/releases/tag/v${{ env.PACKAGE_VERSION }}'
})
dispatch:
name: Repository dispatch
needs: release
runs-on: ubuntu-latest
strategy:
matrix:
repo: ['cieloazul310/ol-gsi-vt-template', 'cieloazul310/railroad-timeline-map']
steps:
- name: Dispatch update-packages
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.PAT }}
repository: ${{ matrix.repo }}
event-type: update-ol-gsi-vt