name: package on: push: branches: [main] # Only a version change produces a release; other commits stay off this path. paths: [version] workflow_dispatch: permissions: contents: write # Releases are ordered: a second run waits instead of racing for the same tag. concurrency: group: package cancel-in-progress: false jobs: package: # Arch containers cannot be stored on the NTFS runner disk: pacman's local # database uses ':' in epoch directory names, which NTFS rejects. The package # is therefore built by makepkg on the Arch host itself. runs-on: arch-host env: REPO_TOKEN: ${{ secrets.REPO_TOKEN }} steps: - uses: actions/checkout@v4 - name: Read the version file id: version run: | set -euo pipefail version="$(tr -d '[:space:]' < version)" if [ -z "$version" ]; then echo "::error file=version::the version file is empty" exit 1 fi echo "version=$version" >> "$GITHUB_OUTPUT" - name: Build the Arch package id: package run: | set -euo pipefail version='${{ steps.version.outputs.version }}' work="$RUNNER_TEMP/build" rm -rf "$work" mkdir -p "$work" cp PKGBUILD version "$work/" git archive --format=tar.gz --prefix="fws-deskmanager-$version/" \ -o "$work/fws-deskmanager-$version.tar.gz" HEAD # makepkg needs the PKGBUILD, the version file it reads and the source # tarball in one directory; the runner's checkout stays untouched. cd "$work" makepkg --noconfirm --nodeps --force --cleanbuild asset="$(ls -1 ./*.pkg.tar.zst | grep -v -- '-debug-' | head -1)" echo "file=$work/${asset##*/}" >> "$GITHUB_OUTPUT" echo "name=${asset##*/}" >> "$GITHUB_OUTPUT" - name: Create the release and attach the package env: GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} run: | set -euo pipefail api="$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY" tag="v${{ steps.version.outputs.version }}" name="${{ steps.package.outputs.name }}" file="${{ steps.package.outputs.file }}" auth="Authorization: token $GITEA_TOKEN" release_id="$(curl -sS -H "$auth" "$api/releases/tags/$tag" | jq -r 'if type == "object" then (.id // empty) else empty end')" if [ -z "$release_id" ]; then body="FWS-DeskManager $version Arch package: \`$name\`" release_id="$(curl -sS --fail-with-body -X POST -H "$auth" -H 'Content-Type: application/json' \ -d "$(jq -n --arg tag "$tag" --arg name "FWS-DeskManager ${{ steps.version.outputs.version }}" \ --arg body "$body" '{tag_name: $tag, name: $name, body: $body, draft: false, prerelease: false}')" \ "$api/releases" | jq -r '.id')" fi # A re-run must not fail on its own previous asset. previous="$(curl -sS -H "$auth" "$api/releases/$release_id/assets" \ | jq -r --arg n "$name" '.[] | select(.name == $n) | .id')" if [ -n "$previous" ]; then curl -sS -X DELETE -H "$auth" "$api/releases/assets/$previous" -o /dev/null fi curl -sS --fail-with-body -X POST -H "$auth" \ -F "attachment=@$file" \ "$api/releases/$release_id/assets?name=$name" -o /dev/null echo "attached $name to release $tag" - name: Publish to repo.laxacube.ch if: env.REPO_TOKEN != '' run: | set -euo pipefail file="${{ steps.package.outputs.file }}" name="${{ steps.package.outputs.name }}" curl -sS --fail-with-body -X POST https://repo.laxacube.ch/api/packages \ -H "Authorization: Bearer $REPO_TOKEN" \ -H "X-Filename: $name" \ -H 'Content-Type: application/octet-stream' \ --data-binary "@$file" echo - name: Warn when the upload token is missing if: env.REPO_TOKEN == '' run: echo "::warning::REPO_TOKEN is not set, the package was released but not published to repo.laxacube.ch"