Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c8daa89

Browse files
committedSep 18, 2023
PROD-3069: Move build logic to reusable workflow
Since cross compiling requires a couple of extra setup, we decided to move the build logic into a reusable workflow so there's only one way of doing things regarding CI. Signed-off-by: Jonnatan Jossemar Cordero <[email protected]>
1 parent 78e330e commit c8daa89

File tree

3 files changed

+76
-63
lines changed

3 files changed

+76
-63
lines changed
 

‎.github/workflows/main.yml

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ on:
1414
tags-ignore:
1515
- '**'
1616

17-
env:
18-
DOCKER_DRIVER: overlay
19-
CARGO_NET_GIT_FETCH_WITH_CLI: true
20-
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER: aarch64-linux-gnu-gcc
21-
2217
jobs:
2318
test:
2419
runs-on: ubuntu-latest
@@ -34,38 +29,8 @@ jobs:
3429
cargo test
3530
3631
build:
37-
runs-on: ubuntu-latest
38-
container: rust:1.72
3932
needs: test
40-
steps:
41-
- uses: actions/checkout@v3
42-
- name: Setup
43-
run: |
44-
rustup target add x86_64-unknown-linux-musl
45-
rustup target add aarch64-unknown-linux-musl
46-
47-
apt-get update
48-
apt-get install -y musl-tools musl-dev
49-
50-
if [ '${{ contains(inputs.arch, 'arm64') }}' = 'true' ]; then
51-
apt-get install -y gcc-aarch64-linux-gnu
52-
fi
53-
54-
- name: Build & package amd64
55-
if: ${{ contains(inputs.arch, 'amd64') }}
56-
run: |
57-
cargo build --release --target x86_64-unknown-linux-musl
58-
./scripts/package ./dist ./target/x86_64-unknown-linux-musl/release
59-
60-
- name: Build & package arm64
61-
if: ${{ contains(inputs.arch, 'arm64') }}
62-
run: |
63-
cargo build --release --target aarch64-unknown-linux-musl
64-
./scripts/package ./dist ./target/aarch64-unknown-linux-musl/release
65-
66-
- name: Archive
67-
uses: actions/upload-artifact@v3
68-
with:
69-
name: package
70-
retention-days: 1
71-
path: dist/*.tar.gz
33+
uses: ./.github/workflows/wc_build_binaries.yml
34+
with:
35+
arch: ${{ inputs.arch }}
36+
artifact_retention: 1

‎.github/workflows/release.yml

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
name: Release
22
on:
3-
push:
4-
tags:
5-
- "v*"
6-
# Workflow dispatch should be used only as fallback method
3+
# Remember to select a Git tag otherwise the workflow will fail
74
workflow_dispatch:
85
inputs:
96
arch:
@@ -20,7 +17,7 @@ env:
2017
CARGO_NET_GIT_FETCH_WITH_CLI: true
2118

2219
jobs:
23-
build:
20+
check:
2421
runs-on: ubuntu-latest
2522
steps:
2623
- uses: actions/checkout@v3
@@ -29,28 +26,24 @@ jobs:
2926
VERSION_IN_CARGO=$(find . -type f -name 'Cargo.toml' -exec grep -oP '^\W*version\W*\K[0-9\.]+' {} \; | sort -nru | head -1)
3027
GIT_TAG='${{ github.ref_name }}'
3128
32-
if [ "${GIT_TAG/#v/}" != "${VERSION_IN_CARGO}" ]; then
33-
echo 'git tag and Cargo.toml version mismatch'
34-
echo "${GIT_TAG/#v/} != ${VERSION_IN_CARGO}"
29+
if [[ "${GIT_TAG/#v/}" != "${VERSION_IN_CARGO}" ]]; then
30+
echo 'Version mismatch between git tag and Cargo.toml'
31+
echo "git: ${GIT_TAG/#v/}"
32+
echo "cargo: ${VERSION_IN_CARGO}"
3533
echo ''
36-
echo 'REMINDER: Git tags must start with "v"'
34+
echo 'REMINDERS:'
35+
echo ' - This workflow must be triggered from a Git tag'
36+
echo ' - Git tags must start with "v"'
3737
exit 1
3838
fi
39-
- name: Setup
40-
run: |
41-
./scripts/build-setup
42-
- name: Build
43-
run: |
44-
./scripts/build ${{ inputs.arch }}
45-
- name: Package
46-
run: |
47-
./scripts/package
48-
- name: Archive
49-
uses: actions/upload-artifact@v3
50-
with:
51-
name: package
52-
retention-days: 7
53-
path: dist/*.tar.gz
39+
shell: bash
40+
41+
build:
42+
needs: check
43+
uses: ./.github/workflows/wc_build_binaries.yml
44+
with:
45+
arch: ${{ inputs.arch }}
46+
artifact_retention: 7
5447

5548
release:
5649
runs-on: ubuntu-latest
@@ -64,5 +57,6 @@ jobs:
6457
- name: Publish release
6558
uses: softprops/action-gh-release@v1
6659
with:
60+
prerelease: true
6761
files: |
6862
dist/*.tar.gz
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: build binaries
2+
on:
3+
workflow_call:
4+
inputs:
5+
arch:
6+
required: false
7+
type: string
8+
default: amd64
9+
artifact_retention:
10+
required: false
11+
type: number
12+
default: 1
13+
14+
env:
15+
DOCKER_DRIVER: overlay
16+
CARGO_NET_GIT_FETCH_WITH_CLI: true
17+
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER: aarch64-linux-gnu-gcc
18+
19+
jobs:
20+
binaries:
21+
runs-on: ubuntu-latest
22+
container: rust:1.72
23+
steps:
24+
- uses: actions/checkout@v3
25+
- name: Setup
26+
run: |
27+
rustup target add x86_64-unknown-linux-musl
28+
rustup target add aarch64-unknown-linux-musl
29+
30+
apt-get update
31+
apt-get install -y musl-tools musl-dev
32+
33+
if [ '${{ contains(inputs.arch, 'arm64') }}' = 'true' ]; then
34+
apt-get install -y gcc-aarch64-linux-gnu
35+
fi
36+
37+
- name: Build & package amd64
38+
if: ${{ contains(inputs.arch, 'amd64') }}
39+
run: |
40+
cargo build --release --target x86_64-unknown-linux-musl
41+
./scripts/package ./target/x86_64-unknown-linux-musl/release
42+
43+
- name: Build & package arm64
44+
if: ${{ contains(inputs.arch, 'arm64') }}
45+
run: |
46+
cargo build --release --target aarch64-unknown-linux-musl
47+
./scripts/package ./target/aarch64-unknown-linux-musl/release
48+
49+
- name: Archive
50+
uses: actions/upload-artifact@v3
51+
with:
52+
name: package
53+
retention-days: ${{ inputs.artifact_retention }}
54+
path: dist/*.tar.gz

0 commit comments

Comments
 (0)
Please sign in to comment.