-
Notifications
You must be signed in to change notification settings - Fork 3
210 lines (178 loc) · 6.53 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
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
on:
release:
types:
- published
workflow_dispatch:
name: Publish binaries
env:
DISABLE_VERSION_CHECK: true
jobs:
validate-version:
name: Validate release (${{ github.event.release.tag_name }})
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: validate version
if: github.event_name == 'release'
run: |
# Extract the version from the Cargo.toml
FP_VERSION=$(cat "Cargo.toml" | grep '^version' | awk '{ split($0,version,"=") ; gsub(/[\ \"]/, "", version[2]) ; print version[2] }')
if [ "v${FP_VERSION}" != "${{ github.event.release.tag_name }}" ]; then
echo "::error file=Cargo.toml::Version set in Cargo.toml (v${FP_VERSION}) does not match release version (${{ github.event.release.tag_name }})"
exit 1
fi
test-release:
needs: validate-version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: de-vri-es/setup-git-credentials@v2
with:
credentials: "https://fiberplanebot:${{ secrets.PRIVATE_GITHUB_TOKEN }}@github.com/"
- uses: Swatinem/rust-cache@v2
- name: Run tests
run: cargo test --release
build-upload-assets:
name: Build assets for ${{ matrix.build }} (${{ github.event.release.tag_name }})
needs: test-release
runs-on: ${{ matrix.os }}
env:
CARGO: cargo
TARGET_FLAGS: ""
TARGET_DIR: ./target
RUST_BACKTRACE: 1
strategy:
matrix:
build: [linux_x86_64, linux_aarch64, macos_x86_64, macos_aarch64]
include:
- build: linux_x86_64
os: ubuntu-latest
rust: stable
target: x86_64-unknown-linux-gnu
- build: linux_aarch64
os: ubuntu-latest
rust: stable
target: aarch64-unknown-linux-gnu
- build: macos_x86_64
os: macOS-11
rust: stable
target: x86_64-apple-darwin
- build: macos_aarch64
os: macOS-11
rust: stable
target: aarch64-apple-darwin
steps:
- uses: actions/checkout@v3
- uses: de-vri-es/setup-git-credentials@v2
with:
credentials: "https://fiberplanebot:${{ secrets.PRIVATE_GITHUB_TOKEN }}@github.com/"
- name: cargo fetch
run: cargo fetch --target ${{ matrix.target }}
- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ matrix.rust }}
profile: minimal
override: true
target: ${{ matrix.target }}
- name: Use Cross
run: |
cargo install cross
echo "CARGO=cross" >> $GITHUB_ENV
echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV
echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV
- name: Show command used for Cargo
run: |
echo "cargo command is: ${{ env.CARGO }}"
echo "target flag is: ${{ env.TARGET_FLAGS }}"
echo "target dir is: ${{ env.TARGET_DIR }}"
- name: Build release binary
run: ${{ env.CARGO }} build --verbose --release ${{ env.TARGET_FLAGS }}
- name: Strip release binary (linux and macos)
if: matrix.build == 'linux_x86_64' || matrix.build == 'macos_x86_64'
run: strip "target/${{ matrix.target }}/release/fp"
- name: Prepare artifact
run: |
mkdir -p /tmp/artifact/
cp "target/${{ matrix.target }}/release/fp" /tmp/artifact/
# We only run x86_64 binaries because this is the platform github runners use
- name: Release version information
if: matrix.build == 'linux_x86_64' || matrix.build == 'macos_x86_64'
run: |
target/${{ matrix.target }}/release/fp version -o verbose
target/${{ matrix.target }}/release/fp version -o json > /tmp/artifact/manifest.json
# - name: Strip release binary (arm)
# if: matrix.build == 'macos_aarch64'
# run: |
# docker run --rm -v \
# "$PWD/target:/target:Z" \
# rustembedded/cross:arm-unknown-linux-gnueabihf \
# arm-linux-gnueabihf-strip \
# /target/arm-unknown-linux-gnueabihf/release/rg
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.target }}
path: /tmp/artifact/
if-no-files-found: error
retention-days: 1
publish-artifacts:
name: Publish artifacts to S3 GitHub build artifact (${{ github.event.release.tag_name }})
runs-on: ubuntu-latest
needs: build-upload-assets
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
path: artifacts
- name: Create SHA256 sums for each artifact
run: |
for dir in artifacts/*/; do
pushd "$dir"
sha256sum * > checksum.sha256
popd
done
- name: Prepare artifacts
if: github.event_name == 'release'
run: |
echo "${{ github.event.release.tag_name }}" | cut -c2- > artifacts/version
- name: Configure AWS Credentials
if: github.event_name == 'release'
uses: aws-actions/configure-aws-credentials@v2
with:
aws-region: eu-central-1
role-to-assume: arn:aws:iam::901443922744:role/github_actions
- name: Generate fp reference
run: |
chmod u+x artifacts/x86_64-unknown-linux-gnu/fp
artifacts/x86_64-unknown-linux-gnu/fp markdown > artifacts/reference.md
- name: Sync fp to S3
if: github.event_name == 'release'
run: |
aws s3 sync \
--acl public-read \
--delete \
artifacts/ \
s3://fp.dev/fp/${{ github.event.release.tag_name }}/
aws s3 sync \
--acl public-read \
--delete \
artifacts/ \
s3://fp.dev/fp/latest
- name: Invalidate latest path on CloudFront
if: github.event_name == 'release'
run: |
aws cloudfront create-invalidation \
--distribution-id "${{ secrets.CF_BUILDS_ID }}" \
--paths '/fp/latest*'
- name: Append front-matter to reference
run: cat files/frontmatter.txt artifacts/reference.md > readme_reference.md
- name: Sync fp reference to ReadMe
uses: readmeio/rdme@v8
env:
RDME_API_KEY: ${{ secrets.README_API_KEY }}
with:
rdme: docs readme_reference.md