-
Notifications
You must be signed in to change notification settings - Fork 52
222 lines (198 loc) · 7.03 KB
/
cd-source.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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
name: CD-Source
on:
# When Pull Request is merged
pull_request_target:
types: [closed]
jobs:
Build-Binaries:
name: Build binaries
if: |
github.event.pull_request.user.login == 'polywrap-build-bot' &&
github.event.pull_request.merged == true
runs-on: ubuntu-latest
strategy:
matrix:
arch:
- x64
- arm64
node-version:
- node18
os:
- linux
- macos
- win
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.base.ref }}
- name: Read VERSION into env.RELEASE_VERSION
run: echo RELEASE_VERSION=$(cat VERSION) >> $GITHUB_ENV
- name: Is Pre-Release
run: |
STR="${RELEASE_VERSION}"
SUB='pre.'
if [[ "$STR" == *"$SUB"* ]]; then
echo PRE_RELEASE=true >> $GITHUB_ENV
else
echo PRE_RELEASE=false >> $GITHUB_ENV
fi
- name: Check If Tag Exists
id: tag_check
shell: bash -ex {0}
run: |
GET_API_URL="https://api.github.com/repos/${{github.repository}}/git/ref/tags/${{env.RELEASE_VERSION}}"
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 TAG_EXISTS=true >> $GITHUB_ENV
else
echo TAG_EXISTS=false >> $GITHUB_ENV
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Read .nvmrc into env.NVMRC
if: env.TAG_EXISTS == 'false'
run: echo NVMRC=$(cat .nvmrc) >> $GITHUB_ENV
- name: Setup Node.js
if: env.TAG_EXISTS == 'false'
uses: actions/setup-node@v1
with:
node-version: '${{env.NVMRC}}'
- name: Install Rust
if: env.TAG_EXISTS == 'false'
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
- name: Build CLI
if: env.TAG_EXISTS == 'false'
run: |
yarn install
yarn build
- name: Package into node binary
if: env.TAG_EXISTS == 'false'
uses: lando/pkg-action@v2
with:
entrypoint: ./packages/cli/bin/polywrap
config: ./packages/cli/package.json
options: --output ./packages/cli/standalone-binaries/${{ matrix.os }}-${{ matrix.arch }}/polywrap --compress Brotli
pkg: 5.8.1
upload: false
arch: ${{ matrix.arch }}
node-version: ${{ matrix.node-version }}
os: ${{ matrix.os }}
- name: Upload Artifacts
if: env.TAG_EXISTS == 'false'
uses: actions/upload-artifact@v3
with:
name: cli-binary-${{ matrix.os }}-${{ matrix.arch }}
path: ${{ steps.pkg-action.outputs.file }}
Publish-GitHub:
name: Publish source to github.com
if: |
github.event.pull_request.user.login == 'polywrap-build-bot' &&
github.event.pull_request.merged == true
needs: Build-Binaries
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.base.ref }}
- name: Read VERSION into env.RELEASE_VERSION
run: echo RELEASE_VERSION=$(cat VERSION) >> $GITHUB_ENV
- name: Is Pre-Release
run: |
STR="${RELEASE_VERSION}"
SUB='pre.'
if [[ "$STR" == *"$SUB"* ]]; then
echo PRE_RELEASE=true >> $GITHUB_ENV
else
echo PRE_RELEASE=false >> $GITHUB_ENV
fi
- name: Check If Tag Exists
id: tag_check
shell: bash -ex {0}
run: |
GET_API_URL="https://api.github.com/repos/${{github.repository}}/git/ref/tags/${{env.RELEASE_VERSION}}"
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 TAG_EXISTS=true >> $GITHUB_ENV
else
echo TAG_EXISTS=false >> $GITHUB_ENV
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set 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: Create Git Tag
if: env.TAG_EXISTS == 'false'
uses: azu/action-package-version-to-git-tag@v1
with:
version: ${{ env.RELEASE_VERSION }}
github_token: ${{ secrets.GITHUB_TOKEN }}
github_repo: ${{ github.repository }}
git_commit_sha: ${{ github.event.pull_request.merge_commit_sha }}
- name: Download Artifacts linux-x64
uses: actions/download-artifact@v3
with:
name: cli-binary-linux-x64
path: ./bin/linux-x64/
- name: Download Artifacts linux-arm64
uses: actions/download-artifact@v3
with:
name: cli-binary-linux-arm64
path: ./bin/linux-arm64/
- name: Download Artifacts macos-x64
uses: actions/download-artifact@v3
with:
name: cli-binary-macos-x64
path: ./bin/macos-x64/
- name: Download Artifacts macos-arm64
uses: actions/download-artifact@v3
with:
name: cli-binary-macos-arm64
path: ./bin/macos-arm64/
- name: Download Artifacts win-x64
uses: actions/download-artifact@v3
with:
name: cli-binary-win-x64
path: ./bin/win-x64/
- name: Download Artifacts win-arm64
uses: actions/download-artifact@v3
with:
name: cli-binary-win-arm64
path: ./bin/win-arm64/
- name: Create Release
id: create_release
if: env.PRE_RELEASE == 'false' && env.TAG_EXISTS == 'false' && github.event.pull_request.merged == true
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.RELEASE_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
files: ./bin
- uses: actions/github-script@0.8.0
if: env.TAG_EXISTS == 'false'
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '**[GitHub Release Published](https://github.com/${{ github.repository }}/releases/tag/${{ env.RELEASE_VERSION }}) `${{env.RELEASE_VERSION}}`** 🎉'
})