-
Notifications
You must be signed in to change notification settings - Fork 0
173 lines (154 loc) · 5.4 KB
/
Copy pathrelease.yml
File metadata and controls
173 lines (154 loc) · 5.4 KB
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
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
dry_run_version:
description: "Version to use for a dry-run build (no tag needed). Leave empty to skip."
required: false
default: ""
permissions:
contents: write
jobs:
build:
name: Build binaries
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
sha_darwin_arm64: ${{ steps.shas.outputs.darwin_arm64 }}
sha_darwin_x64: ${{ steps.shas.outputs.darwin_x64 }}
sha_linux_arm64: ${{ steps.shas.outputs.linux_arm64 }}
sha_linux_x64: ${{ steps.shas.outputs.linux_x64 }}
steps:
- uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Determine version
id: version
run: |
if [ "${GITHUB_REF_TYPE}" = "tag" ]; then
VERSION="${GITHUB_REF_NAME#v}"
elif [ -n "${{ github.event.inputs.dry_run_version }}" ]; then
VERSION="${{ github.event.inputs.dry_run_version }}"
else
VERSION="0.0.0-dryrun.${GITHUB_RUN_NUMBER}"
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "VERSION=${VERSION}"
- name: Build all targets
env:
VERSION: ${{ steps.version.outputs.version }}
run: bash scripts/build-binaries.sh
- name: Extract per-target SHA256
id: shas
run: |
while IFS= read -r line; do
hash=$(awk '{print $1}' <<<"$line")
file=$(awk '{print $2}' <<<"$line" | sed 's#^\*##')
case "$file" in
braincode-darwin-arm64.tar.gz) echo "darwin_arm64=$hash" >> "$GITHUB_OUTPUT" ;;
braincode-darwin-x64.tar.gz) echo "darwin_x64=$hash" >> "$GITHUB_OUTPUT" ;;
braincode-linux-arm64.tar.gz) echo "linux_arm64=$hash" >> "$GITHUB_OUTPUT" ;;
braincode-linux-x64.tar.gz) echo "linux_x64=$hash" >> "$GITHUB_OUTPUT" ;;
esac
done < dist/SHA256SUMS
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: braincode-binaries
path: |
dist/braincode-*.tar.gz
dist/SHA256SUMS
if-no-files-found: error
retention-days: 7
release:
name: GitHub Release
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push' && github.ref_type == 'tag'
steps:
- uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: braincode-binaries
path: dist
- name: Create release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "${GITHUB_REF_NAME}" \
dist/braincode-*.tar.gz \
dist/SHA256SUMS \
--title "${GITHUB_REF_NAME}" \
--generate-notes
npm-publish:
name: Publish to npm
runs-on: ubuntu-latest
needs: [build, release]
if: github.event_name == 'push' && github.ref_type == 'tag'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
registry-url: "https://registry.npmjs.org"
- name: Inject version and publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
VERSION: ${{ needs.build.outputs.version }}
working-directory: apps/cli/npm
run: |
npm version "${VERSION}" --no-git-tag-version --allow-same-version
npm publish --access public
homebrew:
name: Update Homebrew tap
runs-on: ubuntu-latest
needs: [build, release]
if: github.event_name == 'push' && github.ref_type == 'tag'
steps:
- name: Checkout main repo
uses: actions/checkout@v4
with:
path: src
- name: Checkout homebrew-tap
uses: actions/checkout@v4
with:
repository: taotao7/homebrew-tap
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
path: tap
- name: Render formula
env:
VERSION: ${{ needs.build.outputs.version }}
SHA_DARWIN_ARM64: ${{ needs.build.outputs.sha_darwin_arm64 }}
SHA_DARWIN_X64: ${{ needs.build.outputs.sha_darwin_x64 }}
SHA_LINUX_ARM64: ${{ needs.build.outputs.sha_linux_arm64 }}
SHA_LINUX_X64: ${{ needs.build.outputs.sha_linux_x64 }}
run: |
mkdir -p tap/Formula
sed \
-e "s|{{VERSION}}|${VERSION}|g" \
-e "s|{{SHA_DARWIN_ARM64}}|${SHA_DARWIN_ARM64}|g" \
-e "s|{{SHA_DARWIN_X64}}|${SHA_DARWIN_X64}|g" \
-e "s|{{SHA_LINUX_ARM64}}|${SHA_LINUX_ARM64}|g" \
-e "s|{{SHA_LINUX_X64}}|${SHA_LINUX_X64}|g" \
src/scripts/templates/braincode.rb.template > tap/Formula/braincode.rb
cat tap/Formula/braincode.rb
- name: Commit and push
working-directory: tap
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add Formula/braincode.rb
if git diff --cached --quiet; then
echo "no formula changes"
exit 0
fi
git commit -m "braincode ${{ needs.build.outputs.version }}"
git push