ci: stamp deb version with +safelibs<commit-epoch> automatically #7
This file contains hidden or 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
| # AUTO-GENERATED by apt/tools/generate_port_ci.py. Do not edit by | |
| # hand - update repositories.yml or the generator and rerun | |
| # `make generate-port-ci` in the apt checkout. | |
| name: build-debs | |
| on: | |
| push: | |
| pull_request: | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| build: | |
| runs-on: ubuntu-24.04 | |
| env: | |
| IMAGE: ubuntu:24.04 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Prepare output directory | |
| run: mkdir -p "$GITHUB_WORKSPACE/.ci/artifacts" | |
| - name: Write container build script | |
| run: | | |
| set -euo pipefail | |
| mkdir -p .ci | |
| cat >.ci/build.sh <<'SAFELIBS_PORT_CI_SCRIPT' | |
| set -euo pipefail | |
| trap 'chown -R "${HOST_UID}:${HOST_GID}" /workspace/source /workspace/output' EXIT | |
| export DEBIAN_FRONTEND=noninteractive | |
| apt-get update | |
| apt-get install -y --no-install-recommends \ | |
| build-essential \ | |
| ca-certificates \ | |
| devscripts \ | |
| dpkg-dev \ | |
| equivs \ | |
| fakeroot \ | |
| file \ | |
| git \ | |
| jq \ | |
| python3 \ | |
| rsync \ | |
| xz-utils | |
| git config --global --add safe.directory /workspace/source | |
| cd safe | |
| upstream_version=$(dpkg-parsechangelog -S Version | sed -E "s/\+safelibs[0-9]+$//") | |
| package_name=$(dpkg-parsechangelog -S Source) | |
| distribution=$(dpkg-parsechangelog -S Distribution) | |
| commit_epoch=$(git -C "$SAFEAPTREPO_SOURCE" log -1 --format=%ct HEAD) | |
| new_version="${upstream_version}+safelibs${commit_epoch}" | |
| release_date=$(date -u -R -d "@${commit_epoch}") | |
| { | |
| printf "%s (%s) %s; urgency=medium\n\n * Automated SafeLibs rebuild.\n\n -- SafeLibs CI <ci@safelibs.org> %s\n\n" \ | |
| "$package_name" "$new_version" "$distribution" "$release_date" | |
| cat debian/changelog | |
| } > debian/changelog.new | |
| mv debian/changelog.new debian/changelog | |
| mk-build-deps -i -r -t "apt-get -y --no-install-recommends" debian/control | |
| dpkg-buildpackage -us -uc -b | |
| cp -v ../*.deb "$SAFEAPTREPO_OUTPUT"/ | |
| SAFELIBS_PORT_CI_SCRIPT | |
| chmod +x .ci/build.sh | |
| - name: Build safe debs | |
| run: | | |
| set -euo pipefail | |
| docker run --rm \ | |
| --mount "type=bind,src=$GITHUB_WORKSPACE,dst=/workspace/source" \ | |
| --mount "type=bind,src=$GITHUB_WORKSPACE/.ci/artifacts,dst=/workspace/output" \ | |
| -w /workspace/source \ | |
| -e SAFEAPTREPO_SOURCE=/workspace/source \ | |
| -e SAFEAPTREPO_OUTPUT=/workspace/output \ | |
| -e SAFEDEBREPO_SOURCE=/workspace/source \ | |
| -e SAFEDEBREPO_OUTPUT=/workspace/output \ | |
| -e HOST_UID="$(id -u)" \ | |
| -e HOST_GID="$(id -g)" \ | |
| "$IMAGE" \ | |
| bash /workspace/source/.ci/build.sh | |
| - name: List built artifacts | |
| run: ls -la .ci/artifacts | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: debs | |
| path: .ci/artifacts/*.deb | |
| if-no-files-found: error | |
| - name: Publish GitHub release | |
| if: github.event_name == 'push' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| set -euo pipefail | |
| short_sha="${GITHUB_SHA:0:12}" | |
| tag="build-${short_sha}" | |
| title="Build ${short_sha}" | |
| notes="Automated safe-deb build of ${GITHUB_SHA} for $(date -u +%FT%TZ)." | |
| if gh release view "$tag" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then | |
| gh release upload "$tag" --repo "$GITHUB_REPOSITORY" --clobber .ci/artifacts/*.deb | |
| else | |
| gh release create "$tag" \ | |
| --repo "$GITHUB_REPOSITORY" \ | |
| --title "$title" \ | |
| --notes "$notes" \ | |
| --target "$GITHUB_SHA" \ | |
| .ci/artifacts/*.deb | |
| fi |