-
Notifications
You must be signed in to change notification settings - Fork 2
170 lines (163 loc) · 6.43 KB
/
build_then_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
name: Build then release
on:
push:
tags:
- "v*"
branches:
- "main"
env:
CARGO_TERM_COLOR: always
jobs:
gen_version:
name: Generate version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.generated-tag.outputs.tag }}
steps:
- uses: actions/checkout@v4
- name: Get latest tag
id: get-latest-tag
run: |
echo "tag=`gh release list -L 1 | cut -f 1`" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Bump version
id: generated-tag
uses: actions/github-script@v6
with:
script: |
if (context.ref.startsWith("refs/tags/")) {
let tag = context.ref.replace("refs/tags/", "");
core.setOutput('tag', tag);
console.log(`This event pushed a tag ${tag}, return directly.`)
return
}
console.log('Use default tag "prerelease".')
core.setOutput('tag', 'prerelease');
build:
needs: gen_version
name: Build
runs-on: ${{ matrix.runner }}
strategy:
matrix:
include:
- target: x86_64-apple-darwin
runner: macos-latest
build_env: {}
- target: aarch64-apple-darwin
runner: macos-latest
build_env: {}
- target: x86_64-unknown-linux-musl
runner: ubuntu-latest
build_env: {}
- target: aarch64-unknown-linux-musl
runner: ubuntu-latest
build_env:
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS: "-Clink-self-contained=yes -Clinker=rust-lld"
CC_aarch64_unknown_linux_musl: clang
AR_aarch64_unknown_linux_musl: llvm-ar
steps:
- uses: actions/checkout@v4
- name: Setup protoc
uses: arduino/[email protected]
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install musl-tools
if: matrix.runner == 'ubuntu-latest'
run: sudo apt update && sudo apt install -y musl-tools
- name: Install cross build deps for aarch64-unknown-linux-musl
if: matrix.target == 'aarch64-unknown-linux-musl'
run: sudo apt update && sudo apt install -y clang llvm gcc-aarch64-linux-gnu
- name: Add target
run: rustup target add ${{ matrix.target }}
- name: Setup rust toolchain
run: rustup show
- uses: Swatinem/rust-cache@v2
with:
shared-key: build-then-release-${{ matrix.target }}-v1
- name: Build
env: ${{ matrix.build_env }}
run: |
cargo build --release --target ${{ matrix.target }}
- name: Compress
run: |
zip -j dephy-decharge-controller-node-${{ needs.gen_version.outputs.version }}-${{ matrix.target }}.zip ./target/${{ matrix.target }}/release/dephy-decharge-controller-node &&
zip -j dephy-decharge-controller-server-${{ needs.gen_version.outputs.version }}-${{ matrix.target }}.zip ./target/${{ matrix.target }}/release/dephy-decharge-controller-server &&
zip -j dephy-gacha-controller-${{ needs.gen_version.outputs.version }}-${{ matrix.target }}.zip ./target/${{ matrix.target }}/release/dephy-gacha-controller
- uses: actions/upload-artifact@v4
name: Upload artifacts
with:
name: dephy-vending-machine-examples-${{ needs.gen_version.outputs.version }}-${{ matrix.target }}
path: "*.zip"
retention-days: 1
release:
needs: [gen_version, build]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Generate changelog
uses: orhun/git-cliff-action@v3
id: git-cliff
with:
config: cliff.toml
args: "-vv --strip header ${{ needs.gen_version.outputs.version == 'prerelease' && '--unreleased' || '--latest' }}"
- uses: actions/download-artifact@v4
- name: Display fetched artifacts
run: ls -R
- uses: softprops/[email protected]
name: Emit a Github Release
with:
token: "${{ secrets.GITHUB_TOKEN }}"
body: "${{ steps.git-cliff.outputs.content }}"
tag_name: ${{ needs.gen_version.outputs.version }}
prerelease: ${{ needs.gen_version.outputs.version == 'prerelease' }}
files: |
LICENSE
dephy-vending-machine-examples-${{ needs.gen_version.outputs.version }}-x86_64-apple-darwin/*.zip
dephy-vending-machine-examples-${{ needs.gen_version.outputs.version }}-aarch64-apple-darwin/*.zip
dephy-vending-machine-examples-${{ needs.gen_version.outputs.version }}-x86_64-unknown-linux-musl/*.zip
dephy-vending-machine-examples-${{ needs.gen_version.outputs.version }}-aarch64-unknown-linux-musl/*.zip
image:
needs: [gen_version, build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: actions/download-artifact@v4
- name: Log in to the Container registry
uses: docker/[email protected]
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/[email protected]
with:
images: ${{ vars.DOCKERHUB_USERNAME }}/dephy-vending-machine-examples
- name: Extract all released executable files
run: |
for dir in dephy-vending-machine-examples-${{ needs.gen_version.outputs.version }}-*/; do
for zip_file in "$dir"*.zip; do
[ -f "$zip_file" ] && unzip "$zip_file" -d "$dir" && rm "$zip_file"
done
done
- name: Display fetched artifacts
run: ls -R
- name: Move directory for platforms
run: |
mkdir linux &&
mv dephy-vending-machine-examples-${{ needs.gen_version.outputs.version }}-x86_64-unknown-linux-musl linux/amd64 &&
mv dephy-vending-machine-examples-${{ needs.gen_version.outputs.version }}-aarch64-unknown-linux-musl linux/arm64
- name: Display moved files
run: ls -R
- name: Build and push Docker image
id: push
uses: docker/[email protected]
with:
file: ./.github/dockerfiles/dephy-vending-machine-examples.dockerfile
context: .
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
push: true