forked from facebook/buck2
-
Notifications
You must be signed in to change notification settings - Fork 0
229 lines (220 loc) · 7.72 KB
/
upload_buck2.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
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
223
224
225
226
227
228
229
name: Build, upload, and tag `buck2`
on:
push:
branches:
- main
jobs:
get_prelude_hash:
name: Get the latest prelude hash
runs-on: ubuntu-latest
outputs:
prelude_hash: ${{ steps.get_latest_prelude_hash.outputs.prelude_hash }}
steps:
- name: Shallow clone buck2-prelude
run: git clone --depth=1 https://github.com/facebook/buck2-prelude
- name: Get latest commit hash into prelude_hash
id: get_latest_prelude_hash
run: |
mkdir artifacts/
cd buck2-prelude/
git rev-parse HEAD > ../artifacts/prelude_hash
echo "prelude_hash=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- name: Upload prelude_hash
uses: actions/upload-artifact@v3
with:
path: artifacts/prelude_hash
name: prelude_hash
build:
needs:
- get_prelude_hash
strategy:
fail-fast: false
matrix:
target:
- os: 'ubuntu-22.04'
triple: 'aarch64-unknown-linux-gnu'
cross: true
- os: 'ubuntu-22.04'
triple: 'aarch64-unknown-linux-musl'
cross: true
- os: 'ubuntu-22.04'
triple: 'x86_64-unknown-linux-gnu'
- os: 'ubuntu-22.04'
triple: 'x86_64-unknown-linux-musl'
cross: true
- os: 'macos-12'
triple: 'aarch64-apple-darwin'
cross: true
- os: 'macos-12'
triple: 'x86_64-apple-darwin'
- os: 'windows-2022'
triple: 'x86_64-pc-windows-msvc'
is_windows: true
runs-on: ${{ matrix.target.os }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: SebRollen/[email protected]
id: read_rust_toolchain
with:
file: 'rust-toolchain'
field: 'toolchain.channel'
- uses: dtolnay/rust-toolchain@v1
with:
toolchain: ${{ steps.read_rust_toolchain.outputs.value }}
targets: ${{ matrix.target.triple }}
- uses: Swatinem/rust-cache@v2
with:
prefix-key: buck2-upload
key: ${{ matrix.target.triple }}
- uses: actions-rs/[email protected]
if: matrix.target.cross
with:
crate: cross
version: latest
- name: Set variables
id: set_variables
shell: bash
run: |
if [ -n "${{ matrix.target.is_windows }}" ]; then
echo "cargo_out=target/${{ matrix.target.triple }}/release/buck2.exe" >> "$GITHUB_OUTPUT"
echo "buck2_zst=artifacts/buck2-${{ matrix.target.triple }}.exe.zst" >> "$GITHUB_OUTPUT"
else
echo "cargo_out=target/${{ matrix.target.triple }}/release/buck2" >> "$GITHUB_OUTPUT"
echo "buck2_zst=artifacts/buck2-${{ matrix.target.triple }}.zst" >> "$GITHUB_OUTPUT"
fi
- name: Build
shell: bash
env:
RUSTFLAGS: "-C strip=debuginfo -C codegen-units=1"
run: |
if [ -n "${{ matrix.target.cross }}" ]; then
CARGO=cross
else
CARGO=cargo
fi
$CARGO build --release --bin buck2 --target ${{ matrix.target.triple }}
- name: Sanity check with examples/with_prelude
if: ${{ !matrix.target.cross }}
shell: bash
run: |
BUCK2="$(pwd)/${{ steps.set_variables.outputs.cargo_out }}"
cd examples/with_prelude
"$BUCK2" init --git
cd prelude
git checkout ${{ needs.get_prelude_hash.outputs.prelude_hash }}
cd ../
"$BUCK2" build //rust/... //cpp/... //python/... -v=2
- name: Move binary to artifacts/
shell: bash
run: |
mkdir artifacts
zstd -z ${{ steps.set_variables.outputs.cargo_out }} -o ${{ steps.set_variables.outputs.buck2_zst }}
- name: Upload
uses: actions/upload-artifact@v3
with:
name: buck2-${{ matrix.target.triple }}
path: ${{ steps.set_variables.outputs.buck2_zst }}
release_latest:
name: Release `latest` tag
needs:
- build
- get_prelude_hash
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
# Publish a new tag and upload all aritfacts from `build` and `get_prelude_hash`
- uses: ./.github/actions/publish_tag
with:
tag: "latest"
github_token: ${{ secrets.GITHUB_TOKEN }}
check_for_bi_monthly_release:
name: Check if there's a release for this half of the month already
runs-on: ubuntu-latest
needs:
- build
outputs:
tag: ${{ steps.check_if_we_need_to_tag.outputs.new_tag }}
steps:
- id: get_date
name: Store date information so we stay consistent between the steps
run: |
month=$(date +%Y-%m)
day=$(date +%d)
tag=$(date +%Y-%m-%d)
echo "month=$month" >> "$GITHUB_OUTPUT"
echo "day=$day" >> "$GITHUB_OUTPUT"
echo "tag=$tag" >> "$GITHUB_OUTPUT"
cat "$GITHUB_OUTPUT"
- id: get_tags_count
name: Count the number of tags already published for this month
run: |
url="https://api.github.com/repos/facebook/buck2/tags"
curl --retry 5 -fsSL "$url" -o tags.txt
tags=$(cat tags.txt | jq -r ".[].name")
tags_count=$(echo "$tags" | grep -c "${{ steps.get_date.outputs.month }}" || true)
echo "tags_count=$tags_count" >> "$GITHUB_OUTPUT"
cat "$GITHUB_OUTPUT"
- id: check_if_we_need_to_tag
name: Check if we should tag
run: |
tags_count=${{ steps.get_tags_count.outputs.tags_count }}
day=${{ steps.get_date.outputs.day }}
tag=${{ steps.get_date.outputs.tag }}
# If we're in the first half of the month, check if there are no tags for this month yet
if (( day < 15 && tags_count < 1 )); then echo "new_tag=${tag}" >> "$GITHUB_OUTPUT"; fi;
# Otherwise, tag if the count is less than 2.
if (( day >= 15 && tags_count < 2 )); then echo "new_tag=${tag}" >> "$GITHUB_OUTPUT"; fi;
cat $GITHUB_OUTPUT
release_bi_monthly:
name: Release bi-monthly tag
needs:
- build
- check_for_bi_monthly_release
runs-on: ubuntu-latest
# Only perform this action if check_for_bi_monthly_release set a tag output
if: ${{ needs.check_for_bi_monthly_release.outputs.tag }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
# Publish a new tag and upload all aritfacts from `build` and `get_prelude_hash`
- uses: ./.github/actions/publish_tag
with:
tag: ${{ needs.check_for_bi_monthly_release.outputs.tag }}
github_token: ${{ secrets.GITHUB_TOKEN }}
build_docs_job:
name: Publish buck2.build
runs-on: ubuntu-latest
needs:
- build
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download Buck2
uses: actions/download-artifact@v3
with:
name: buck2-x86_64-unknown-linux-gnu
path: artifacts
- name: Decompress Buck2
run: |
zstd -d artifacts/buck2-x86_64-unknown-linux-gnu.zst -o artifacts/buck2-release
chmod +x artifacts/buck2-release
- name: Install dependencies
run: |
sudo apt-get install -y yarn
id: build
- name: Build the Website
run: |
cd website
yarn
BUCK2_BIN="$GITHUB_WORKSPACE/artifacts/buck2-release" yarn build_prebuilt
- name: Deploy
uses: JamesIves/github-pages-deploy-action@releases/v4
with:
branch: gh-pages # The branch the action should deploy to.
folder: website/build # The folder the action should deploy.
single-commit: true # Discard history for the gh-pages branch.