-
Notifications
You must be signed in to change notification settings - Fork 0
205 lines (203 loc) · 7.45 KB
/
build_pkg.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
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
201
202
203
204
205
name: build
on:
workflow_call:
inputs:
repository:
type: string
default: ${{ github.repository }}
ref:
type: string
default: ${{ github.sha }}
build_container:
type: string
default: ghcr.io/gardenlinux/package-build
source:
type: string
default: ""
debian_source:
type: string
default: ""
dependencies:
type: string
default: ""
email:
type: string
default: ""
maintainer:
type: string
default: ""
distribution:
type: string
default: ""
message:
type: string
default: ""
env:
GH_TOKEN: ${{ github.token }}
jobs:
source:
name: source package
outputs:
pkg: ${{ steps.build.outputs.pkg }}
build_options: ${{ steps.build.outputs.build_options }}
release: ${{ steps.release.outputs.release }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: gardenlinux/package-build
ref: feature/5-remove-pkg-yml
- run: mkdir input output
- uses: actions/checkout@v4
with:
repository: ${{ inputs.repository }}
ref: ${{ inputs.ref }}
path: input
- name: check if HEAD contains tag
id: tagged
needs: test
if: github.ref_type !== 'tag'
run: |
echo "Commit is not tagged. Cancel the workflow!"
gh run cancel ${{ github.run_id }}
fi
- name: pull build container
run: podman pull "${{ inputs.build_container }}:amd64"
- name: fetch dependencies
run: |
mkdir _pkgs
while IFS=@ read -r repo tag; do
./scripts/gh_release "${{ github.token }}" "$repo" list "$tag" | grep '\.deb$' | while read -r url; do
(cd _pkgs && wget "$url")
done
done <<< '${{ inputs.dependencies }}'
ls -lah _pkgs
(cd _pkgs && dpkg-scanpackages --multiversion . > Packages)
cat _pkgs/Packages
- name: build
id: build
env:
GITHUB_REF_TYPE: ${{ github.ref_type }}
GITHUB_REF_NAME: ${{ github.ref_name }}
run: |
version=""
[ "$GITHUB_REF_TYPE" == "tag" ] && version=${GITHUB_REF_NAME#*/}
pkg="$(podman run \
--rm \
--mount="type=bind,src=$PWD/${GITHUB_ACTION_PATH}/container/bin,dst=/usr/local/sbin,ro" \
-e PACKAGE_VERSION="$version" \
-v "$PWD/input:/input" \
-v "$PWD/output:/output" \
-v "$PWD/_pkgs:/pkgs" \
"${{ inputs.build_container }}:amd64" build_source
)"
echo "pkg=$pkg" | tee -a "$GITHUB_OUTPUT"
echo "build_options=$(cat output/.build_options)" | tee -a "$GITHUB_OUTPUT"
echo "source_name=$(cat output/.source_name)" | tee -a "$GITHUB_OUTPUT"
- name: check if ${{ env.pkg }} already released
id: check
run: |
if ./scripts/gh_release "${{ github.token }}" "${{ github.repository }}" exists "${{ steps.build.outputs.pkg }}"; then
echo "skip_release=true" | tee "$GITHUB_OUTPUT"
else
echo "skip_release=false" | tee "$GITHUB_OUTPUT"
fi
- name: draft release and upload source packages
id: release
if: ${{ steps.check.outputs.skip_release != 'true' }}
env:
PKG_NAME: ${{ steps.build.outputs.pkg }}
run: |
tag="gardenlinux/${PKG_NAME#${{ steps.build.outputs.source_name }}_}"
release="$(./scripts/gh_release "${{ github.token }}" "${{ github.repository }}" create --draft "$tag" "${{ github.sha }}" "${{ steps.build.outputs.pkg }}")"
for f in output/*; do
./scripts/gh_release "${{ github.token }}" "${{ github.repository }}" upload "$release" "$f"
done
echo "release=$release" | tee "$GITHUB_OUTPUT"
packages:
name: ${{ matrix.target == 'indep' && 'architecture independent packages' || format('{0} binary packages', matrix.arch) }}
needs: source
if: ${{ needs.source.outputs.release != '' }}
runs-on: ubuntu-latest
strategy:
matrix:
target: [ indep, archdep ]
arch: [ amd64, arm64v8 ]
exclude:
- target: indep
arch: arm64v8
steps:
- uses: actions/checkout@v4
with:
repository: gardenlinux/package-build
ref: feature/5-remove-pkg-yml
- name: setup binfmt
if: ${{ matrix.arch == 'arm64v8' }}
run: sudo podman run --privileged ghcr.io/gardenlinux/binfmt_container
- name: pull build container
run: podman pull "${{ inputs.build_container }}:${{ matrix.arch }}"
- name: get source package
run: |
mkdir input
cd input
pkg="${{ needs.source.outputs.pkg }}"
release="${{ needs.source.outputs.release }}"
../scripts/gh_release "${{ github.token }}" "${{ github.repository }}" download "$release" "$pkg.dsc"
awk '!/^ / { flag=0 } flag { print $NF } /^Files:/ { flag=1 }' < "$pkg.dsc" | while read -r file; do
../scripts/gh_release "${{ github.token }}" "${{ github.repository }}" download "$release" "$file"
done
echo "${{ needs.source.outputs.build_options }}" > .build_options
ln -s "$pkg.dsc" .source
- name: fetch dependencies
run: |
mkdir _pkgs
while IFS=@ read -r repo tag; do
./scripts/gh_release "${{ github.token }}" "$repo" list "$tag" | grep '\.deb$' | while read -r url; do
(cd _pkgs && wget "$url")
done
done <<< '${{ inputs.dependencies }}'
ls -lah _pkgs
(cd _pkgs && dpkg-scanpackages --multiversion . > Packages)
cat _pkgs/Packages
- name: build
id: build
run: |
mkdir output
pkg="$(podman run \
--rm \
--mount="type=bind,src=$PWD/${GITHUB_ACTION_PATH}/container/bin,dst=/usr/local/sbin,ro" \
-v "$PWD/input:/input" \
-v "$PWD/output:/output" \
-v "$PWD/_pkgs:/pkgs" \
"${{ inputs.build_container }}:${{ matrix.arch }}" \
"build_${{ matrix.target }}"
)"
echo "pkg=$pkg" | tee -a "$GITHUB_OUTPUT"
- name: upload packages
if: ${{ steps.build.outputs.pkg != '' }}
run: |
release="${{ needs.source.outputs.release }}"
for f in output/*; do
./scripts/gh_release "${{ github.token }}" "${{ github.repository }}" upload "$release" "$f"
done
publish:
needs: [ source, packages ]
if: ${{ needs.source.outputs.release != '' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: gardenlinux/package-build
ref: feature/5-remove-pkg-yml
- name: publish drafted release
run: ./scripts/gh_release "${{ github.token }}" "${{ github.repository }}" publish_draft "${{ needs.source.outputs.release }}"
cleanup:
needs: [ source, packages ]
if: ${{ always() && contains(needs.*.result, 'failure') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: gardenlinux/package-build
- name: delete drafted release
run: ./scripts/gh_release "${{ github.token }}" "${{ github.repository }}" delete "${{ needs.source.outputs.release }}"