Repository navigation
169 lines (139 loc) · 5.4 KB
/
Copy pathrelease-linux-gnu.yml
File metadata and controls
169 lines (139 loc) · 5.4 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
name: Release Linux x86_64 GNU
on:
workflow_run:
workflows: ["Verify GPG Signature"]
types:
- completed
branches: ["stable"]
permissions:
contents: write
packages: write
id-token: write
jobs:
standard:
name: ${{ matrix.features }}-${{ matrix.target }}
runs-on: ubuntu-latest
strategy:
matrix:
target: [x86_64-unknown-linux-gnu]
features: ["default", "osk"]
fail-fast: false
env:
APP_NAME: "eQ"
APP_PATH: "target/${{ matrix.target }}/release"
OUTPUT_DIR: "${{ github.workspace }}/LAB7041/${{ matrix.target }}"
CHANGELOG: "doc/changelog.md"
steps:
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y pkg-config
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache cargo dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Install Rust
uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c
with:
targets: ${{ matrix.target }}
components: clippy rustfmt
- name: Check code
run: |
cargo fmt --
cargo clippy --no-deps --verbose --locked --features "${{ matrix.features }}" --target ${{ matrix.target }} -- -D warnings
- name: Build project
run: |
echo "Building with features: ${{ matrix.features }}"
cargo build --release --verbose --locked --target ${{ matrix.target }} --features "${{ matrix.features }}"
- name: Tests project
run: |
cargo test --release --locked --verbose --no-fail-fast --target ${{ matrix.target }} --features "${{ matrix.features }}"
- id: extract_version
name: Extract version number
run: |
VERSION_NUMBER=$(head -n 1 "${{ env.CHANGELOG }}" | cut -d ':' -f 2- | tr -d ' #version' | xargs)
if [[ ! "$VERSION_NUMBER" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: VERSION_NUMBER is not in valid format: ${VERSION_NUMBER}"
echo "Expected format: 1.2.3"
exit 1
fi
echo "VERSION_NUMBER=${VERSION_NUMBER}" >> $GITHUB_OUTPUT
- name: Create tag
run: |
git config user.name "${{ env.APP_NAME }}"
git config user.email "${{ secrets.ACTIONS_EMAIL }}"
VERSION="v${{ steps.extract_version.outputs.VERSION_NUMBER }}"
echo "Checking if tag $VERSION exists..."
if [ -n "$(git ls-remote --tags origin "$VERSION")" ]; then
echo "Tag $VERSION already exists on remote, skipping."
else
echo "Tag $VERSION does not exist on remote. Creating new signed tag."
# Create an annotated tag; if you use GPG signing, ensure the runner has access to the key
if ! git tag -a "$VERSION" -m "Release $VERSION"; then
echo "GPG signing or tag creation failed"
exit 1
fi
if ! git push origin "$VERSION"; then
echo "Tag push failed"
exit 1
fi
echo "Tag $VERSION created successfully."
fi
- id: prepare_release
name: Prepare release files
run: |
BIN_DIR="target/${{ matrix.target }}/release"
APP_NAME="${{ env.APP_NAME }}"
FEATURES="${{ matrix.features }}"
VERSION="${{ steps.extract_version.outputs.VERSION_NUMBER }}"
TARGET="${{ matrix.target }}"
BIN_FILE="${APP_NAME}"
OUTPUT_BIN="${APP_NAME}-${VERSION}"
TAR_FILE="${APP_NAME}-${VERSION}-${FEATURES}-Linux.tar.gz"
set -euo pipefail
if [ ! -f "${BIN_DIR}/${BIN_FILE}" ]; then
echo "Error: binary ${BIN_DIR}/${BIN_FILE} not found"
exit 1
fi
strip "${BIN_DIR}/${BIN_FILE}" || true
mkdir -p "${OUTPUT_DIR}"
cp "${BIN_DIR}/${BIN_FILE}" "${OUTPUT_DIR}/${OUTPUT_BIN}"
cp "${{ env.CHANGELOG }}" "${OUTPUT_DIR}/changelog.md"
cp LICENSE "${OUTPUT_DIR}/LICENSE"
tar -czf "${OUTPUT_DIR}/${TAR_FILE}" \
-C "${OUTPUT_DIR}" "${OUTPUT_BIN}" \
-C "${OUTPUT_DIR}" "changelog.md" \
-C "${OUTPUT_DIR}" "LICENSE"
echo "TAR_FILE=${TAR_FILE}" >> $GITHUB_OUTPUT
echo "Release files prepared"
- name: Generate SHA256 checksum
run: |
set -euo pipefail
TAR="${{ env.OUTPUT_DIR }}/${{ steps.prepare_release.outputs.TAR_FILE }}"
if [ ! -f "${TAR}" ]; then
echo "Error: ${TAR} not found"
exit 1
fi
sha256sum "${TAR}" > "${TAR}.sha256"
- name: Upload to GitHub Releases
uses: softprops/action-gh-release@3d0d9888cb7fd7b750713d6e236d1fcb99157228
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: |
${{ env.OUTPUT_DIR }}/${{ steps.prepare_release.outputs.TAR_FILE }}
${{ env.OUTPUT_DIR }}/${{ steps.prepare_release.outputs.TAR_FILE }}.sha256
${{ env.CHANGELOG }}
LICENSE
draft: false
prerelease: true
tag_name: v${{ steps.extract_version.outputs.VERSION_NUMBER }}