forked from MostroP2P/mostro-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
153 lines (136 loc) · 4.32 KB
/
rust.yml
File metadata and controls
153 lines (136 loc) · 4.32 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
name: Build and Test for all targets
on:
push:
tags: ['v*.*.*'] # run only when a tag like v1.2.3 is pushed
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
jobs:
# Generate changelog (runs once)
changelog:
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
content: ${{ steps.changelog.outputs.content }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
token: ${{ secrets.GITHUB_TOKEN }}
- name: Ensure all tags are present
run: git fetch --tags --force --prune
- name: Generate changelog
uses: orhun/git-cliff-action@v4
id: changelog
with:
config: cliff.toml
# Use the latest tag vs previous tag automatically
args: --latest --strip header --output CHANGELOG.md
env:
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REF: ${{ github.ref }}
# Test the code
test:
runs-on: ubuntu-latest
needs: changelog
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Cache cargo
uses: Swatinem/rust-cache@v2
with: { cache-on-failure: true }
- name: cargo test
run: cargo test --locked
# Prepare matrix of targets from archs file
matrix:
runs-on: ubuntu-latest
needs: test
outputs:
targets: ${{ steps.set-matrix.outputs.targets }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- id: set-matrix
name: Read targets from archs
shell: bash
run: |
set -euo pipefail
targets=$(grep -v '^\s*$' archs | jq -R -s -c 'split("\n") | map(select(length>0))')
echo "targets=$targets" >> "$GITHUB_OUTPUT"
# Build binaries for all targets using cross
build:
runs-on: ubuntu-latest
needs: matrix
strategy:
fail-fast: false
matrix:
target: ${{ fromJSON(needs.matrix.outputs.targets) }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Cache cross binary
id: cache-cross
uses: actions/cache@v4
with:
path: ~/.cargo/bin/cross
key: cross-${{ runner.os }}-0.2.5
- name: Install cross ( pinned version for reproducibility )
if: steps.cache-cross.outputs.cache-hit != 'true'
run: cargo install cross --version 0.2.5
- name: Build release
run: cross build --release --locked --target ${{ matrix.target }}
- name: Prepare conventional artifact name
shell: bash
run: |
set -euo pipefail
outdir="artifacts"
mkdir -p "$outdir"
case "${{ matrix.target }}" in
*-pc-windows-*) src="target/${{ matrix.target }}/release/mostro-cli.exe"; dst="$outdir/mostro-cli-${{ matrix.target }}.exe";;
*) src="target/${{ matrix.target }}/release/mostro-cli"; dst="$outdir/mostro-cli-${{ matrix.target }}";;
esac
cp "$src" "$dst"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: artifact-${{ matrix.target }}
path: artifacts/*
# Create release with all artifacts
release:
runs-on: ubuntu-latest
needs: [changelog, build]
permissions:
contents: write
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
- name: Generate checksums manifest
shell: bash
run: |
set -euo pipefail
shopt -s globstar nullglob
# Compute SHA256 for all produced binaries
: > manifest.txt
for f in $(ls -1 artifact-*/mostro-cli* | sort); do
sha256sum "$f" >> manifest.txt
done
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
body: ${{ needs.changelog.outputs.content }}
files: |
artifact-*/mostro-cli*
manifest.txt
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}