name: Build & Publish on: push: branches: ["main"] paths: - "CHANGELOG.md" workflow_dispatch: {} jobs: check: runs-on: ubuntu-latest outputs: should_build: ${{ steps.version_check.outputs.should_build }} version: ${{ steps.version_check.outputs.version }} pkg_version: ${{ steps.version_check.outputs.pkg_version }} short_sha: ${{ steps.version_check.outputs.short_sha }} owner: ${{ steps.meta.outputs.owner }} repo: ${{ steps.meta.outputs.repo }} steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 2 - name: Repo meta (owner/repo) id: meta shell: bash run: | set -e # Gitea Actions is GitHub-compatible; this usually exists. FULL="${GITHUB_REPOSITORY:-}" if [ -z "$FULL" ]; then echo "GITHUB_REPOSITORY is empty. Set it in runner env or switch to explicit OWNER/REPO vars." exit 1 fi OWNER="${FULL%%/*}" REPO="${FULL##*/}" echo "owner=$OWNER" >> "$GITHUB_OUTPUT" echo "repo=$REPO" >> "$GITHUB_OUTPUT" - name: Check version change in CHANGELOG id: version_check shell: bash run: | set -e OLD=$(git show HEAD~1:CHANGELOG.md | grep '^## \[' | head -1 || true) NEW=$(grep '^## \[' CHANGELOG.md | head -1 || true) echo "Old: $OLD" echo "New: $NEW" # Extract x.y.z from: ## [x.y.z] - YYYY-MM-DD VERSION=$(echo "$NEW" | sed -n 's/^## \[\([0-9]\+\.[0-9]\+\.[0-9]\+\)\].*$/\1/p') if [ -z "$VERSION" ]; then echo "Could not parse version from CHANGELOG.md (expected: ## [x.y.z] - YYYY-MM-DD)" exit 1 fi SHORT_SHA="$(git rev-parse --short=7 HEAD)" PKG_VERSION="${VERSION}+g${SHORT_SHA}" echo "Parsed VERSION=$VERSION" echo "SHORT_SHA=$SHORT_SHA" echo "PKG_VERSION=$PKG_VERSION" if [ "$OLD" = "$NEW" ]; then echo "should_build=false" >> "$GITHUB_OUTPUT" else echo "should_build=true" >> "$GITHUB_OUTPUT" fi echo "version=$VERSION" >> "$GITHUB_OUTPUT" echo "short_sha=$SHORT_SHA" >> "$GITHUB_OUTPUT" echo "pkg_version=$PKG_VERSION" >> "$GITHUB_OUTPUT" build_publish: needs: check if: needs.check.outputs.should_build == 'true' runs-on: ubuntu-latest container: image: archlinux:latest steps: - name: Install deps (Arch) run: | pacman -Syu --noconfirm --needed \ base-devel git ca-certificates curl tar gzip \ rust cargo - name: Checkout uses: actions/checkout@v4 - name: Create source tarball (code) shell: bash run: | set -e OWNER="${{ needs.check.outputs.owner }}" REPO="${{ needs.check.outputs.repo }}" PKG_VERSION="${{ needs.check.outputs.pkg_version }}" mkdir -p dist # Clean source snapshot of the repository at current commit git archive --format=tar.gz \ --prefix="${REPO}-${PKG_VERSION}/" \ -o "dist/${REPO}-${PKG_VERSION}-source.tar.gz" \ HEAD ls -lh dist # OPTIONAL: build binary and package it too - name: Build (release) shell: bash run: | set -e cargo build --release - name: Collect binary shell: bash run: | set -e REPO="${{ needs.check.outputs.repo }}" PKG_VERSION="${{ needs.check.outputs.pkg_version }}" mkdir -p dist cp "target/release/${REPO}" "dist/${REPO}-${PKG_VERSION}-linux-x86_64" chmod +x "dist/${REPO}-${PKG_VERSION}-linux-x86_64" ls -lh dist - name: Upload to Gitea Generic Packages shell: bash env: GITEA_BASE_URL: ${{ vars.GITEA_BASE_URL }} GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} run: | set -e OWNER="${{ needs.check.outputs.owner }}" REPO="${{ needs.check.outputs.repo }}" PKG_VERSION="${{ needs.check.outputs.pkg_version }}" if [ -z "${GITEA_BASE_URL:-}" ]; then echo "Missing vars.GITEA_BASE_URL (example: https://gitea.example.com)" exit 1 fi if [ -z "${GITEA_TOKEN:-}" ]; then echo "Missing secrets.GITEA_TOKEN" exit 1 fi # Choose a package name (keep stable). Here: repo name. PACKAGE_NAME="$REPO" for FILE in dist/*; do FILENAME="$(basename "$FILE")" URL="${GITEA_BASE_URL}/api/packages/${OWNER}/generic/${PACKAGE_NAME}/${PKG_VERSION}/${FILENAME}" echo "Uploading $FILENAME -> $URL" curl -fsS -X PUT \ -H "Authorization: token ${GITEA_TOKEN}" \ --upload-file "$FILE" \ "$URL" done