-
Notifications
You must be signed in to change notification settings - Fork 10
144 lines (127 loc) · 5.47 KB
/
publish.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
name: publish
on:
# pull_request:
push:
branches:
- master
tags:
- "*"
env:
CARGO_TERM_COLOR: always
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
# https://users.rust-lang.org/t/cross-compiling-how-to-statically-link-glibc/83907/2
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER: aarch64-linux-gnu-gcc
jobs:
create-release:
name: Create GitHub release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
- name: Create release
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v2
with:
prerelease: ${{ contains(github.ref, '-') }}
build-release:
name: Build release binaries for ${{ matrix.target }}
needs: [create-release]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: windows-latest
target: x86_64-pc-windows-msvc
- os: windows-latest
target: aarch64-pc-windows-msvc
- os: macos-latest
target: x86_64-apple-darwin
- os: macos-latest
target: aarch64-apple-darwin
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
- os: ubuntu-latest
target: aarch64-unknown-linux-musl
steps:
- uses: actions/checkout@v4
- name: Setup extra build tools
if: matrix.target == 'aarch64-unknown-linux-musl'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Build
run: |
cargo build --verbose --bin=pacaptr --release --locked --target=${{ matrix.target }}
# https://github.com/vercel/turbo/blob/ea934d13038361c24a1f71cad3b490d6c0936f37/.github/workflows/turborepo-release.yml#L268-L272
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: pacaptr-${{ matrix.target }}
path: target/${{ matrix.target }}/release/pacaptr*
retention-days: 1
publish:
name: Publish via GoReleaser
needs: [build-release]
runs-on: ubuntu-latest
container:
# NOTE: It is also possible to install `choco` directly:
# https://github.com/JetBrains/qodana-cli/blob/29134e654dc4878e0587f02338c5101bce327560/.github/workflows/release.yml#L19-L27
image: chocolatey/choco:latest-linux
steps:
- name: Setup build essential
run: |
apt-get update && apt-get install -y git curl build-essential
- uses: actions/checkout@v4
- name: Setup Golang
uses: actions/setup-go@v5
with:
go-version: stable
# https://github.com/vercel/turbo/blob/ea934d13038361c24a1f71cad3b490d6c0936f37/.github/workflows/turborepo-release.yml#L306-L309
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: target/gh-artifacts
# Here we use `mv` to map Rust targets to Golang ones.
# https://github.com/vercel/turbo/blob/ea934d13038361c24a1f71cad3b490d6c0936f37/.github/workflows/turborepo-release.yml#L313-L318
- name: Modify and inspect artifacts
shell: bash
run: |
echo $PWD
chown -R $(id -u):$(id -g) $PWD
chmod -R 744 target/gh-artifacts
ls -laR target/gh-artifacts
mv -f target/gh-artifacts/pacaptr-x86_64-pc-windows-msvc target/gh-artifacts/pacaptr_windows_amd64
mv -f target/gh-artifacts/pacaptr-aarch64-pc-windows-msvc target/gh-artifacts/pacaptr_windows_arm64
mv -f target/gh-artifacts/pacaptr-x86_64-apple-darwin target/gh-artifacts/pacaptr_darwin_amd64
mv -f target/gh-artifacts/pacaptr-aarch64-apple-darwin target/gh-artifacts/pacaptr_darwin_arm64
mv -f target/gh-artifacts/pacaptr-x86_64-unknown-linux-musl target/gh-artifacts/pacaptr_linux_amd64
mv -f target/gh-artifacts/pacaptr-aarch64-unknown-linux-musl target/gh-artifacts/pacaptr_linux_arm64
echo '======='
ls -laR target/gh-artifacts
# https://goreleaser.com/ci/actions/?h=github+act#usage
- name: Publish via GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
args: release --clean --verbose ${{ github.event_name == 'push' && contains(github.ref, 'refs/tags/') && ' ' || '--snapshot --skip=publish' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAP_GITHUB_TOKEN: ${{ secrets.TAP_GITHUB_TOKEN }}
CHOCO_API_KEY: ${{ secrets.CHOCO_API_KEY }}
# https://github.com/goreleaser/goreleaser/blob/2a3009757a8996cdcf2a77deb0e5fa413d1f2660/internal/pipe/chocolatey/chocolatey.go#L158
- name: Inspect generated artifacts
run: |
ls -laR dist/
cat dist/pacaptr.choco/pacaptr.nuspec
# https://github.com/goreleaser/goreleaser/blob/2a3009757a8996cdcf2a77deb0e5fa413d1f2660/internal/pipe/chocolatey/chocolatey.go#L201-L208
# https://stackoverflow.com/a/75835172
- name: Publish app on Chocolatey
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
run: |
choco push dist/*.nupkg --source https://push.chocolatey.org --api-key ${{ secrets.CHOCO_API_KEY }} --verbose ${{ contains(github.ref, '-') && '--noop' || ' ' }}