Repository navigation
200 lines (162 loc) · 6.16 KB
/
Copy pathrpm.yml
File metadata and controls
200 lines (162 loc) · 6.16 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
name: Fedora RPM
on:
pull_request:
push:
branches:
- main
- master
schedule:
- cron: '17 3 * * *'
workflow_dispatch:
inputs:
force_build:
description: Force a build even when no commits were added since the last RPM release
required: false
default: true
type: boolean
permissions:
contents: write
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
rpm-ci:
if: github.event_name == 'push' || github.event_name == 'pull_request'
runs-on: ubuntu-latest
container:
image: fedora:41
steps:
- name: Install build dependencies
run: |
dnf -y update
dnf -y install \
git \
rpm-build \
rpmdevtools \
cargo \
rust \
- name: Checkout repository
uses: actions/checkout@v5
- name: Mark workspace as a safe Git directory
run: git config --global --add safe.directory "${GITHUB_WORKSPACE}"
- name: Build SRPM/RPM
run: |
set -euo pipefail
version="$(awk -F '"' '/^version = / {print $2; exit}' Cargo.toml)"
topdir="$(rpm --eval '%{_topdir}')"
rpmdev-setuptree
archive_dir="rustyuki-${version}"
tarball="${archive_dir}.tar.gz"
git archive --format=tar.gz --prefix="${archive_dir}/" -o "${topdir}/SOURCES/${tarball}" HEAD
cp .github/rpm/rustyuki.spec "${topdir}/SPECS/rustyuki.spec"
sed -i "s/^Version:.*/Version: ${version}/" "${topdir}/SPECS/rustyuki.spec"
rpmbuild -ba "${topdir}/SPECS/rustyuki.spec"
mkdir -p dist
find "${topdir}/RPMS" -type f -name '*.rpm' -exec cp {} dist/ \;
find "${topdir}/SRPMS" -type f -name '*.src.rpm' -exec cp {} dist/ \;
- name: Upload RPM artifacts
uses: actions/upload-artifact@v5
with:
name: fedora-rpm-ci-${{ github.run_number }}
path: dist/*
if-no-files-found: error
rpm-release:
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
container:
image: fedora:41
steps:
- name: Install build dependencies
run: |
dnf -y update
dnf -y install \
git \
rpm-build \
rpmdevtools \
cargo \
rust \
gh \
jq
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Mark workspace as a safe Git directory
run: git config --global --add safe.directory "${GITHUB_WORKSPACE}"
- name: Decide whether a build is needed
id: plan
env:
GH_TOKEN: ${{ github.token }}
EVENT_NAME: ${{ github.event_name }}
FORCE_BUILD: ${{ github.event.inputs.force_build || 'false' }}
run: |
set -euo pipefail
latest_tag="$(gh api repos/${GITHUB_REPOSITORY}/releases --jq '[.[] | select(.tag_name | startswith("rpm-nightly-"))][0].tag_name' || true)"
head_sha="$(git rev-parse HEAD)"
should_build=false
reason=""
if [[ "${EVENT_NAME}" == "workflow_dispatch" && "${FORCE_BUILD}" == "true" ]]; then
should_build=true
reason="manual force build"
elif [[ -z "${latest_tag}" || "${latest_tag}" == "null" ]]; then
should_build=true
reason="no previous rpm-nightly release"
else
last_sha="$(git rev-list -n 1 "${latest_tag}")"
if [[ "${head_sha}" != "${last_sha}" ]]; then
should_build=true
reason="new commits since ${latest_tag}"
else
reason="no new commits since ${latest_tag}"
fi
fi
release_tag="rpm-nightly-$(date -u +%Y%m%d)"
{
echo "latest_tag=${latest_tag}"
echo "head_sha=${head_sha}"
echo "should_build=${should_build}"
echo "reason=${reason}"
echo "release_tag=${release_tag}"
} >> "$GITHUB_OUTPUT"
echo "Build decision: ${should_build} (${reason})"
- name: Stop early when there are no new commits
if: steps.plan.outputs.should_build != 'true'
run: |
echo "Skipping build: ${{ steps.plan.outputs.reason }}"
- name: Build SRPM/RPM using Fedora rpm macros
if: steps.plan.outputs.should_build == 'true'
run: |
set -euo pipefail
version="$(awk -F '"' '/^version = / {print $2; exit}' Cargo.toml)"
topdir="$(rpm --eval '%{_topdir}')"
rpmdev-setuptree
archive_dir="rustyuki-${version}"
tarball="${archive_dir}.tar.gz"
git archive --format=tar.gz --prefix="${archive_dir}/" -o "${topdir}/SOURCES/${tarball}" HEAD
cp .github/rpm/rustyuki.spec "${topdir}/SPECS/rustyuki.spec"
sed -i "s/^Version:.*/Version: ${version}/" "${topdir}/SPECS/rustyuki.spec"
rpmbuild -ba "${topdir}/SPECS/rustyuki.spec"
mkdir -p dist
find "${topdir}/RPMS" -type f -name '*.rpm' -exec cp {} dist/ \;
find "${topdir}/SRPMS" -type f -name '*.src.rpm' -exec cp {} dist/ \;
- name: Upload RPM artifacts
if: steps.plan.outputs.should_build == 'true'
uses: actions/upload-artifact@v5
with:
name: fedora-rpm-${{ steps.plan.outputs.release_tag }}
path: dist/*
if-no-files-found: error
- name: Create GitHub release for RPMs
if: steps.plan.outputs.should_build == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.plan.outputs.release_tag }}
target_commitish: ${{ steps.plan.outputs.head_sha }}
name: Fedora RPM build ${{ steps.plan.outputs.release_tag }}
generate_release_notes: true
files: dist/*
body: |
Automated Fedora RPM build.
- Trigger: `${{ github.event_name }}`
- Reason: `${{ steps.plan.outputs.reason }}`
- Commit: `${{ steps.plan.outputs.head_sha }}`
- Previous RPM tag: `${{ steps.plan.outputs.latest_tag || 'none' }}`