-
Notifications
You must be signed in to change notification settings - Fork 18
135 lines (116 loc) · 3.83 KB
/
build.yml
File metadata and controls
135 lines (116 loc) · 3.83 KB
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
name: release
on:
push:
branches:
- main
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
# Keep pull request builds for testing
pull_request:
workflow_dispatch:
permissions:
contents: write
jobs:
version:
name: Generate Version
runs-on: ubuntu-latest
outputs:
new_tag: ${{ steps.tag_version.outputs.new_tag }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/github-tag-action@v6.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
default_bump: patch
release_branches: main
build:
name: Build
needs: version
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
artifact_name: popcorn-cli
asset_name: popcorn-cli-linux.tar.gz
compress_cmd: tar -czf
compress_ext: .tar.gz
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact_name: popcorn-cli
asset_name: popcorn-cli-windows.zip
compress_cmd: 7z a
compress_ext: .zip
- os: macos-latest
target: aarch64-apple-darwin
artifact_name: popcorn-cli
asset_name: popcorn-cli-macos.tar.gz
compress_cmd: tar -czf
compress_ext: .tar.gz
steps:
- uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
targets: ${{ matrix.target }}
- name: Set up cargo cache
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Install cross-compilation dependencies (Linux ARM)
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
- name: Install musl tools (Linux musl)
if: matrix.target == 'x86_64-unknown-linux-musl'
run: |
sudo apt-get update
sudo apt-get install -y musl-tools
- name: Build release binary
run: cargo build --release --target ${{ matrix.target }}
env:
CLI_VERSION: ${{ needs.version.outputs.new_tag }}
- name: Prepare artifact
shell: bash
run: |
mkdir -p dist
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
cp target/${{ matrix.target }}/release/popcorn-cli.exe dist/popcorn-cli.exe
else
cp target/${{ matrix.target }}/release/popcorn-cli dist/popcorn-cli
chmod +x dist/popcorn-cli
fi
cd dist
${{ matrix.compress_cmd }} ../${{ matrix.asset_name }} *
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.asset_name }}
path: ${{ matrix.asset_name }}
retention-days: 7
release:
name: Create Release
needs: [build, version]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main'
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.version.outputs.new_tag }}
name: Release ${{ needs.version.outputs.new_tag }}
files: |
popcorn-cli-linux.tar.gz/popcorn-cli-linux.tar.gz
popcorn-cli-windows.zip/popcorn-cli-windows.zip
popcorn-cli-macos.tar.gz/popcorn-cli-macos.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}