Building package only if it's tagged. #5
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }}" |