-
Notifications
You must be signed in to change notification settings - Fork 77
177 lines (155 loc) · 5.32 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
167
168
169
170
171
172
173
174
175
176
name: 'openapi-ws release-v2'
on:
workflow_dispatch: {}
release:
types:
- published
env:
SKIP_ANNOUNCE: 'false'
SKIP_PUBLISH: 'false'
jobs:
verify-prerelease-tag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Verify prerelease has a prerelease tag
if: github.event.release.prerelease
run: |
if ! [[ "${{ github.event.release.tag_name }}" =~ ^v[0-9]+.[0-9]+.[0-9]+\-.+ ]]
then
echo "ERROR: '${{ github.event.release.tag_name }}' is not a valid prerelease tag"
exit 1
fi
verify-versions-agree:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Confirm GH release and package.json agree on version
if: github.event_name == 'release'
run: |
# add a 'v' prefix to match the Git tag
package_version=v$(jq -r '.version' < package.json)
if [ "${package_version}" != "${{ github.event.release.tag_name }}" ]
then
echo "ERROR: package.json version (${package_version}) does not match GitHub release tag (${{ github.event.release.tag_name }})"
exit 1
fi
- name: Confirm all package.json files have the same version
run: .github/scripts/version-sync
verify-version-unpublished:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Confirm release version is unpublished
run: |
package_version=$(jq -r '.version' < package.json)
is_published=$(
yarn npm info "@useoptic/openapi-utilities" --json \
| jq -rs '.[0]' \
| jq ".versions // []" \
| jq -r "any(.[]; . == \"$package_version\")"
)
if [ "${is_published}" == "true" ]
then
echo "ERROR: @useoptic/openapi-utilities@$package_version is already published"
exit 1
fi
release:
runs-on: ubuntu-latest-16-core
needs:
- verify-prerelease-tag
- verify-versions-agree
- verify-version-unpublished
outputs:
optic_version: ${{ steps.version.outputs.optic_version }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
cache: yarn
- name: Install Task
run: curl -sL https://taskfile.dev/install.sh | sudo bash -s -- -b /usr/local/bin/
- name: Build
env:
NODE_ENV: production
run: |
set -a
source projects/optic/.env.production
task default
- name: Test
run: task test
- name: Set NPM credentials
run: yarn config set 'npmScopes.useoptic.npmAuthToken' "${{ secrets.PUBLISH_NPM_OPTIC_BOT }}"
- name: Set release channel to 'prerelease'
run: echo "RELEASE_CHANNEL=prerelease" >> $GITHUB_ENV
- name: Set release channel to 'latest'
if: github.event_name == 'release'
run: |
if [[ "${{ github.event.release.prerelease }}" == "false" ]]
then
echo "Setting RELEASE_CHANNEL to 'latest'"
echo "RELEASE_CHANNEL=latest" >> $GITHUB_ENV
else
echo "Leaving RELEASE_CHANNEL as '$RELEASE_CHANNEL'"
fi
- name: Get package version
id: version
run: |
v=$(jq -r .version < package.json)
echo "VERSION=$v" >> $GITHUB_ENV
echo "optic_version=v${v}" >> $GITHUB_OUTPUT
- name: Publish NPM
run: |
if [ "$SKIP_PUBLISH" = "false" ]
then
echo "Publishing $VERSION to the "$RELEASE_CHANNEL" channel"
cp README.md ./projects/optic/README.md
task publish -- --tag $RELEASE_CHANNEL
else
echo "SKIP_PUBLISH=$SKIP_PUBLISH"
echo "Would publish $VERSION to the "$RELEASE_CHANNEL" channel"
fi
- name: Announce success
uses: slackapi/slack-github-action@v1.24.0
if: >
success()
&& env.SKIP_ANNOUNCE == 'false'
&& env.SKIP_PUBLISH == 'false'
env:
SLACK_WEBHOOK_URL: ${{ secrets.BUILD_BOT_SLACK_WEBHOOK_URL_RELEASES }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
with:
payload: |
{
"text": "${{github.actor}}: ✅ optic v${{env.VERSION}} packages published to channel `${{env.RELEASE_CHANNEL}}`!"
}
- name: Announce failure
uses: slackapi/slack-github-action@v1.24.0
if: >
failure()
&& env.SKIP_ANNOUNCE == 'false'
&& env.SKIP_PUBLISH == 'false'
env:
SLACK_WEBHOOK_URL: ${{ secrets.BUILD_BOT_SLACK_WEBHOOK_URL_RELEASES }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
with:
payload: |
{
"text": "${{github.actor}}: 🚫 optic v${{env.VERSION}} failed to publish."
}
publish-binaries:
needs: release
uses: ./.github/workflows/release-binaries.yml
with:
release_tag_name: ${{ github.event.release.tag_name }}
secrets: inherit
publish-container-image:
needs:
- release
- publish-binaries
if: github.event.release.prerelease == false
uses: ./.github/workflows/release-container-image.yml
with:
optic_version: ${{ needs.release.outputs.optic_version }}
secrets: inherit