From 9183f32bbe46bd712a82c55a047d9af3292fd364 Mon Sep 17 00:00:00 2001 From: Thomas Willetal Date: Fri, 31 Oct 2025 00:08:07 +0100 Subject: [PATCH] Add GitHub Actions for manual release and Debian version parsing --- .github/actions/build-deb/action.yml | 69 +++++++++++++++++++ .github/actions/get-deb-version/action.yml | 30 ++++++++ .../actions/trigger-and-wait-build/action.yml | 60 ++++++++++++++++ .github/workflows/ci-build.yml | 52 +++++--------- .github/workflows/release.yml | 44 ++++++++++++ .gitignore | 2 +- 6 files changed, 220 insertions(+), 37 deletions(-) create mode 100644 .github/actions/build-deb/action.yml create mode 100644 .github/actions/get-deb-version/action.yml create mode 100644 .github/actions/trigger-and-wait-build/action.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/actions/build-deb/action.yml b/.github/actions/build-deb/action.yml new file mode 100644 index 0000000..3b90fe3 --- /dev/null +++ b/.github/actions/build-deb/action.yml @@ -0,0 +1,69 @@ +name: "Build Debian packages with Podman" +description: "Builds Debian packages for amd64 and arm64" +author: "Thomas Willetal" + +inputs: + path: + description: "Path to the Debian package directory (for changelog parsing)" + required: true + +outputs: + version: + description: "Parsed Debian version from changelog" + value: ${{ steps.changelog.outputs.version }} + +runs: + using: "composite" + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install dependencies (Podman, Python, dpkg-dev) + shell: bash + run: | + sudo apt-get update + sudo apt-get install -y podman python3-pip dpkg-dev + + - name: Install podman-compose from PyPI + shell: bash + run: | + pip install --upgrade pip + pip install podman-compose + + - name: Verify Podman and podman-compose + shell: bash + run: | + podman --version + podman-compose version + + - name: Prepare build environment + shell: bash + run: make builder + + - name: Build amd64 package + shell: bash + run: make amd64-debbuild + + - name: Build arm64 package + shell: bash + run: make arm64-debbuild + + - name: Get Debian version + id: changelog + uses: ./.github/actions/get-deb-version + with: + path: ${{ inputs.path }} + + - name: Show parsed version + shell: bash + run: echo "Version=${{ steps.changelog.outputs.version }}" + + - name: Upload build artifacts + if: success() + uses: actions/upload-artifact@v4 + with: + name: uds-daemon-example-${{ steps.changelog.outputs.version }} + path: | + **/*.deb + **/*.changes + **/*.buildinfo diff --git a/.github/actions/get-deb-version/action.yml b/.github/actions/get-deb-version/action.yml new file mode 100644 index 0000000..9379db3 --- /dev/null +++ b/.github/actions/get-deb-version/action.yml @@ -0,0 +1,30 @@ +name: "Get Debian Package Version" +description: "Parse Debian version from a debian/changelog file" + +inputs: + path: + description: "Path to the folder containing debian/changelog" + required: false + default: '.' + +outputs: + version: + description: "Version extracted from debian/changelog" + value: ${{ steps.parse.outputs.version }} + +runs: + using: "composite" + steps: + - name: Parse Debian version + id: parse + shell: bash + working-directory: ${{ inputs.path }} + run: | + set -e + if [ ! -f debian/changelog ]; then + echo "error debian/changelog not found" + exit 1 + fi + VERSION=$(dpkg-parsechangelog --show-field Version) + echo "Detected version: $VERSION" + echo "version=$VERSION" >> "$GITHUB_OUTPUT" diff --git a/.github/actions/trigger-and-wait-build/action.yml b/.github/actions/trigger-and-wait-build/action.yml new file mode 100644 index 0000000..54ebff4 --- /dev/null +++ b/.github/actions/trigger-and-wait-build/action.yml @@ -0,0 +1,60 @@ +name: "Trigger and Wait for CI Build" +description: "Triggers another workflow and waits until it completes successfully." +author: "Thomas Willetal" + +inputs: + workflow: + description: "Name or ID of the workflow to trigger" + required: true + ref: + description: "Git ref or branch to trigger the workflow on" + required: true + default: ${{ github.ref_name }} + poll_interval: + description: "Seconds between status checks" + required: false + default: "30" + token: + description: "GitHub token or PAT for workflow dispatch" + required: true + +runs: + using: "composite" + steps: + - name: Install GitHub CLI + shell: bash + run: | + sudo apt-get update -y + sudo apt-get install -y gh jq + + - name: Trigger workflow and wait for completion + shell: bash + env: + GITHUB_TOKEN: ${{ inputs.token }} + INPUT_WORKFLOW: ${{ inputs.workflow }} + INPUT_REF: ${{ inputs.ref }} + INPUT_POLL_INTERVAL: ${{ inputs.poll_interval }} + run: | + echo "Triggering workflow '$INPUT_WORKFLOW' on ref '$INPUT_REF'..." + gh workflow run "$INPUT_WORKFLOW" --ref "$INPUT_REF" + + echo "Waiting for the workflow to start..." + sleep 10 + + echo "Polling workflow status every $INPUT_POLL_INTERVAL seconds..." + while true; do + STATUS=$(gh run list --workflow "$INPUT_WORKFLOW" --branch "$INPUT_REF" --limit 1 --json status,conclusion -q '.[0].status') + CONCLUSION=$(gh run list --workflow "$INPUT_WORKFLOW" --branch "$INPUT_REF" --limit 1 --json status,conclusion -q '.[0].conclusion') + echo "Current status: $STATUS / $CONCLUSION" + + if [[ "$STATUS" == "completed" ]]; then + if [[ "$CONCLUSION" == "success" ]]; then + echo "Workflow succeeded" + exit 0 + else + echo "Workflow failed: $CONCLUSION" + exit 1 + fi + fi + sleep "$INPUT_POLL_INTERVAL" + done diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 0708d36..90b7776 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -1,10 +1,11 @@ -name: Podman Compose Build +name: ci-build on: push: branches: [ main ] pull_request: branches: [ main ] + workflow_dispatch: jobs: build: @@ -14,39 +15,18 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Install Podman - run: | - sudo apt-get update - sudo apt-get install -y podman python3-pip - - - name: Install podman-compose from PyPI - run: | - pip install --upgrade pip - pip install podman-compose - - - name: Verify installation - run: | - podman --version - podman-compose version - - - name: Make builder - run: | - make builder - - - name: amd64 debbuild - run: | - make amd64-debbuild - - - name: arm64 debbuild - run: | - make arm64-debbuild - - - name: Upload build artifacts - if: success() - uses: actions/upload-artifact@v4 + - name: Build Debian packages + uses: ./.github/actions/build-deb with: - name: debian-packages - path: | - **/*.deb - **/*.changes - **/*.buildinfo + path: "uds-daemon-example" + + - name: Get Debian version + id: changelog + uses: ./.github/actions/get-deb-version + with: + path: "uds-daemon-example" + + - name: Show parsed version + run: echo Version=${{ steps.changelog.outputs.version }} + + diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..9afe8cb --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,44 @@ +name: Release + +on: + workflow_dispatch: + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Run Debian build + id: builddeb + uses: ./.github/actions/build-deb + with: + path: "uds-daemon-example" + + - name: Show Debian version + run: echo "Built version is ${{ steps.builddeb.outputs.version }}" + + - name: Download build artifacts + uses: actions/download-artifact@v4 + with: + name: uds-daemon-example-${{ steps.builddeb.outputs.version }} + path: ./release-artifacts + + - name: Show downloaded files + run: ls -l release-artifacts + + - name: Create GitHub Release + if: github.ref == 'refs/heads/main' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + VERSION="${{ steps.builddeb.outputs.version }}" + TAG="v${VERSION}" + gh release create "${TAG}" \ + --title "Release ${TAG}" \ + --notes "Automated release for version ${TAG}" \ + ./release-artifacts/* + + diff --git a/.gitignore b/.gitignore index 5b8897b..7a688a0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ *.deb *.changes *.log -!.github/workflows/*.yml \ No newline at end of file +!.github \ No newline at end of file