-
Notifications
You must be signed in to change notification settings - Fork 8
130 lines (129 loc) · 4.86 KB
/
ci.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
name: Continuous Integration (CI)
on:
push:
branches:
- main
jobs:
test:
runs-on: ubuntu-22.04
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: Swatinem/rust-cache@v2
- name: cargo test
run: |
rustup component add rustfmt
cargo check
cargo fmt --check
cargo test --workspace
release:
name: release ${{ matrix.binary.name }} ${{ matrix.arch.name }}
needs: [test]
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
binary:
- workspace: .
name: freighter
arch:
- name: amd64
runtime-image: "debian@sha256:9b42b2e7eddd84eaddb67b45567cdc0e03ec826bf252352f300147cfb8ce5a6d"
- name: aarch64
runtime-image: "debian@sha256:c583ed77e10b69b167c09cba3d82f903a9a7af481cbb75166d5307135f7b2c77"
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
- name: Setup QEMU
if: matrix.arch.name != 'amd64'
run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
- name: Setup Rust
run: |
rm -rf ~/.cargo
docker run -d --name=init \
-v $PWD/${{ matrix.binary.workspace }}:/repo/ -w /repo \
ghcr.io/innopals/rust-centos7:$(cat rust-toolchain)-${{ matrix.arch.name }} \
tail -f /etc/issue
docker cp init:/root/.cargo ~/.cargo
mkdir -p ${HOME}/.local/bin
cd ${HOME}/.local/bin
echo '#!/bin/bash' > rustc
echo 'docker exec init rustc $@' > rustc
echo '#!/bin/bash' > cargo
echo 'docker exec init cargo $@' > cargo
chmod +x *
rustc -vV
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.binary.workspace }}/${{ matrix.binary.name }}-${{ matrix.arch.name }}
cache-on-failure: true
workspaces: ${{ matrix.binary.workspace }} -> target
- name: Start Build Container
run: |
docker run -d --name=build \
-v $PWD/${{ matrix.binary.workspace }}:/repo/ -v $HOME/.cargo:/root/.cargo -w /repo \
ghcr.io/innopals/rust-centos7:$(cat rust-toolchain)-${{ matrix.arch.name }} \
tail -f /etc/issue
- name: Build Artifacts
run: |
docker exec build bash -c 'set -e
cargo build --release
strip target/release/${{ matrix.binary.name }}
cp target/release/${{ matrix.binary.name }} target/release/${{ matrix.binary.name }}-${{ matrix.arch.name }}
'
sudo chown -R runner:docker ${{ matrix.binary.workspace }}/target
sudo chown -R runner:docker $HOME/.cargo
- name: Publish Artifacts
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
with:
files: |
${{ matrix.binary.workspace }}/target/release/${{ matrix.binary.name }}-${{ matrix.arch.name }}
- name: Draft Artifacts
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
uses: softprops/action-gh-release@v1
with:
draft: true
name: "latest"
tag_name: "latest"
files: |
${{ matrix.binary.workspace }}/target/release/${{ matrix.binary.name }}-${{ matrix.arch.name }}
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Nightly Docker Image
run: |
export IMAGE_TAG="ghcr.io/${{ github.repository }}-nightly:${{ matrix.arch.name }}-${{ github.sha }}"
echo "Building image $IMAGE_TAG"
docker buildx build \
--push \
--build-arg RUNTIME_IMAGE=${{ matrix.arch.runtime-image }} \
-t $IMAGE_TAG .
release-image:
if: startsWith(github.ref, 'refs/tags/')
name: release docker image
needs: [release]
runs-on: ubuntu-22.04
steps:
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Publish Docker Image
run: |
docker pull ghcr.io/${{ github.repository }}-nightly:amd64-${{ github.sha }}
docker pull ghcr.io/${{ github.repository }}-nightly:aarch64-${{ github.sha }}
export IMAGE_TAG="ghcr.io/${{ github.repository }}:${{ github.ref_name }}"
docker manifest create $IMAGE_TAG \
--amend ghcr.io/${{ github.repository }}-nightly:amd64-${{ github.sha }} \
--amend ghcr.io/${{ github.repository }}-nightly:aarch64-${{ github.sha }}
docker manifest push --purge $IMAGE_TAG