-
Notifications
You must be signed in to change notification settings - Fork 96
209 lines (184 loc) · 6.76 KB
/
release-cli.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
name: "Release CLI"
on:
workflow_dispatch:
pull_request_target:
types:
- closed
paths:
- "cli/**"
jobs:
push-tag:
if: github.event_name == 'workflow_dispatch' || (github.event.pull_request.merged == true && !contains(github.event.pull_request.body, 'release skip'))
runs-on: ubuntu-20.04
outputs:
version: ${{ steps.version.outputs.VERSION }}
steps:
- name: Checkout /buildbuddy
uses: actions/checkout@v3
with:
# We need to fetch git tags to obtain the latest cli version tag.
fetch-depth: 0
- name: Push tag
run: |
git config --local user.email "github-actions-release-bot@users.noreply.github.com"
git config --local user.name "github-actions-release[bot]"
./cli/release.py --auto
- name: Get CLI version
id: version
run: |
version=$(git tag -l 'cli-v*' --sort=creatordate |
perl -nle 'if (/^cli-v(\d+\.\d+\.\d+)$/) { print $1 }' |
tail -n1)
echo $version
echo "VERSION=$version" >> "$GITHUB_OUTPUT"
create-release:
runs-on: ubuntu-20.04
needs: push-tag
steps:
- name: Checkout buildbuddy-io/bazel
uses: actions/checkout@v3
with:
repository: buildbuddy-io/bazel
path: bazel-fork
token: ${{ secrets.BUILDBUDDY_GITHUB_USER_TOKEN }}
- name: Create draft release
env:
GITHUB_TOKEN: ${{ secrets.BUILDBUDDY_GITHUB_USER_TOKEN }}
run: |
set -x # print executed commands
if gh release view ${{ needs.push-tag.outputs.version }} --repo=buildbuddy-io/bazel; then
echo "buildbuddy-io/bazel release ${{ needs.push-tag.outputs.version }} already exists."
# It's OK if the release already exists; the build-artifacts job will just overwrite
# any existing artifacts.
exit 0
fi
TAG=${{ needs.push-tag.outputs.version }}
cd "${GITHUB_WORKSPACE}/bazel-fork"
git fetch --all --tags
if [[ "$(git tag -l "$TAG")" ]]; then
echo "Tag $TAG already exists."
else
git tag "$TAG"
git push origin "$TAG"
fi
gh release create "$TAG" \
--repo=buildbuddy-io/bazel --title="$TAG" --draft --notes="Release version $TAG"
sync-plugins:
runs-on: ubuntu-20.04
needs: [push-tag, create-release]
steps:
- name: Checkout buildbuddy-io/buildbuddy
uses: actions/checkout@v3
with:
path: buildbuddy
- name: Checkout buildbuddy-io/plugins
uses: actions/checkout@v3
with:
repository: buildbuddy-io/plugins
path: plugins
token: ${{ secrets.BUILDBUDDY_GITHUB_USER_TOKEN }}
- name: Sync plugins and push version tag
env:
GITHUB_TOKEN: ${{ secrets.BUILDBUDDY_GITHUB_USER_TOKEN }}
VERSION: ${{ needs.push-tag.outputs.version }}
run: |
set -e
cd "${GITHUB_WORKSPACE}/plugins"
git checkout main
git pull
git config --local user.name "BuildBuddy Bot"
git config --local user.email "hello@buildbuddy.io"
# Commit and push changes to cli/plugins dir from buildbuddy repo
# Remove any existing plugin directories in the plugins repo.
# Note, this implementation assumes all top-level directories
# are plugin directories (except the .git directory)
EXISTING_PLUGIN_DIRS=($(find . -mindepth 1 -maxdepth 1 -type d | grep -v './\.git'))
echo "Removing existing plugin dirs:" "${EXISTING_PLUGIN_DIRS[@]}"
rm -rf "${EXISTING_PLUGIN_DIRS[@]}"
# Copy all top-level plugin directories to the top-level of the
# plugins repo.
PLUGIN_DIRS=($(find "${GITHUB_WORKSPACE}/buildbuddy/cli/plugins" -mindepth 1 -maxdepth 1 -type d))
cp -r "${PLUGIN_DIRS[@]}" ./
# Commit and push the plugin dirs.
git add .
commit_output=$(mktemp)
if git commit -m "Update plugins to v${VERSION}" 2>&1 | tee "${commit_output}"; then
git push
elif grep 'nothing to commit' "${commit_output}" &>/dev/null; then
echo "No plugin changes in version $VERSION"
else
echo "Commit failed; exiting"
exit 1
fi
# Push new tag to match CLI release.
TAG="v${VERSION}"
git tag "$TAG"
git push origin "$TAG"
build-artifacts:
strategy:
matrix:
include:
- os: ubuntu-20.04
- os: ubuntu-22.04-16cpu-arm64-arm-limited # linux arm64
- os: macos-13 # macOS amd64
- os: macos-13-xlarge # macOS arm64
runs-on: ${{ matrix.os }}
needs: [push-tag, create-release]
steps:
- name: Clean workspace
run: |
set -x
ls -la ./
rm -rf ./* || true
rm -rf ./.??* || true
ls -la ./
- name: Checkout
uses: actions/checkout@v3
with:
path: buildbuddy
- name: Build Artifacts
id: build
env:
XCODE_VERSION: 12.4
run: |
set -x # print executed commands
if [[ "$OSTYPE" == darwin* ]]; then
OS=darwin
else
OS=linux
fi
ARCH=$(uname -m)
# bazelisk uses "x86_64" / "arm64" convention
if [[ "$ARCH" == "aarch64" ]]; then
ARCH=arm64
fi
VERSION=${{ needs.push-tag.outputs.version }}
cd "${GITHUB_WORKSPACE}/buildbuddy"
bazelisk build //cli/cmd/bb \
--remote_header=x-buildbuddy-api-key=${{ secrets.BUILDBUDDY_ORG_API_KEY }} \
--//cli/version:cli_version="$VERSION"
BINARY="bazel-${VERSION}-${OS}-${ARCH}"
cp bazel-bin/cli/cmd/bb/bb_/bb "$BINARY"
shasum -a 256 "$BINARY" > "${BINARY}.sha256"
echo "BINARY=${BINARY}" >> "$GITHUB_OUTPUT"
- name: Upload Artifacts
env:
GITHUB_TOKEN: ${{ secrets.BUILDBUDDY_GITHUB_USER_TOKEN }}
run: |
set -x # print executed commands
cd "${GITHUB_WORKSPACE}/buildbuddy"
gh release upload \
--repo buildbuddy-io/bazel \
--clobber \
"${{ needs.push-tag.outputs.version }}" \
"${{ steps.build.outputs.BINARY }}" \
"${{ steps.build.outputs.BINARY }}.sha256"
publish-release:
runs-on: ubuntu-20.04
needs: [push-tag, sync-plugins, build-artifacts]
steps:
- name: Publish release
env:
GITHUB_TOKEN: ${{ secrets.BUILDBUDDY_GITHUB_USER_TOKEN }}
run: |
gh release edit ${{ needs.push-tag.outputs.version }} --draft=false --repo=buildbuddy-io/bazel