# SPDX-FileCopyrightText: 2023-2026 Sayantan Santra # SPDX-License-Identifier: MIT name: Test and Release on: push: tags: - "*" branches: ["dev"] paths: ["backend/**", "frontend/**"] workflow_dispatch: env: CARGO_TERM_COLOR: always IMAGE_NAME: chhoto-url jobs: # Build artifacts build: name: Build and Test - ${{ matrix.platform.os-name }} if: | github.ref_type == 'tag' || !startsWith(github.event.head_commit.message, 'build: Bumped version to') strategy: matrix: platform: - os-name: Linux-x86_64 target: x86_64-unknown-linux-musl - os-name: Linux-arm64 target: aarch64-unknown-linux-musl - os-name: Linux-armv7 target: armv7-unknown-linux-musleabihf - os-name: Linux-riscv64 target: riscv64gc-unknown-linux-musl # Need to use an unreleased version for now cross-version: a5c1c64f0810eb90c790e94b7904b27dccc02287 runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v6 - name: Compute short SHA id: vars shell: bash run: echo "short_sha=$(echo ${{ github.sha }} | cut -c1-7)" >> "$GITHUB_OUTPUT" # Build the binaries and upload - name: Build binary and test uses: houseabsolute/actions-rust-cross@v1 env: CARGO_GIT_COMMIT: ${{ github.ref_type != 'tag' && steps.vars.outputs.short_sha || '' }} with: command: both target: ${{ matrix.platform.target }} args: "--locked --release --manifest-path=backend/Cargo.toml" cross-version: ${{ matrix.platform.cross-version }} rust-cache-parameters: '{"workspaces":"backend -> target"}' - name: Upload artifacts uses: actions/upload-artifact@v7 with: name: ${{ matrix.platform.target }} path: ./backend/target/${{ matrix.platform.target }}/release/${{ env.IMAGE_NAME }} retention-days: 1 if-no-files-found: error # Push dev image dev: name: Push dev image if: github.ref_type != 'tag' runs-on: ubuntu-latest permissions: id-token: write contents: write packages: write attestations: write needs: build steps: # Prep the files - name: Checkout repository uses: actions/checkout@v6 with: lfs: true fetch-depth: 0 - name: Download artifacts uses: actions/download-artifact@v8 - name: Move stuff around and fix permissions run: | for f in *-unknown-linux-musl* do mkdir -p backend/target/$f/release mv $f/chhoto-url backend/target/$f/release/ chmod +x backend/target/$f/release/chhoto-url done - name: Display current directory structure run: ls -R - name: Log in to the Container registry uses: docker/login-action@v4 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} # Extract metadata - name: Extract metadata (tags, labels) for Docker - dev id: meta-dev uses: docker/metadata-action@v6 env: DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index with: images: | ghcr.io/sintan1729/${{ env.IMAGE_NAME }} tags: | type=raw,value=dev # Build and push docker images - name: Set up Docker Buildx uses: docker/setup-buildx-action@v4 - name: Build and push Docker image - dev id: push-dev uses: docker/build-push-action@v7 with: context: . push: true file: deploy/Containerfile.alpine tags: ${{ steps.meta-dev.outputs.tags }} labels: ${{ steps.meta-dev.outputs.labels }} platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/riscv64 annotations: ${{ steps.meta-dev.outputs.annotations }} # Attestation - name: Generate artifact attestation - dev uses: actions/attest@v4 with: subject-name: sintan1729/${{ env.IMAGE_NAME }} subject-digest: ${{ steps.push-dev.outputs.digest }} # Push release images release: name: Push release images if: github.ref_type == 'tag' runs-on: ubuntu-latest permissions: id-token: write contents: write packages: write attestations: write needs: build steps: # Prep the files - name: Checkout repository uses: actions/checkout@v6 with: lfs: true fetch-depth: 0 - name: Download artifacts uses: actions/download-artifact@v8 - name: Move stuff around and fix permissions run: | for f in *-unknown-linux-musl* do mkdir -p backend/target/$f/release mv $f/chhoto-url backend/target/$f/release/ chmod +x backend/target/$f/release/chhoto-url done - name: Minify frontend for release run: | mv frontend/ frontend-original/ sudo apt update sudo apt install minify minify -rs frontend-original/ -o frontend/ mkdir -p empty-dir # Needed for scratch - name: Display current directory structure run: ls -R - name: Log in to the Docker Hub uses: docker/login-action@v4 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Log in to the Container registry uses: docker/login-action@v4 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} # Extract metadata - name: Extract metadata (tags, labels) for Docker - alpine id: meta-alpine uses: docker/metadata-action@v6 env: DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index with: images: | sintan1729/${{ env.IMAGE_NAME }} ghcr.io/sintan1729/${{ env.IMAGE_NAME }} tags: | type=semver,pattern={{major}}-alpine type=semver,pattern={{major}}.{{minor}}-alpine type=semver,pattern={{version}}-alpine type=raw,value=latest-alpine type=raw,value=alpine - name: Extract metadata (tags, labels) for Docker - scratch id: meta-scratch uses: docker/metadata-action@v6 env: DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index with: images: | sintan1729/${{ env.IMAGE_NAME }} ghcr.io/sintan1729/${{ env.IMAGE_NAME }} tags: | type=semver,pattern={{major}} type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{version}} type=raw,value=latest type=raw,value=scratch # Build and push docker images - name: Set up Docker Buildx uses: docker/setup-buildx-action@v4 - name: Build and push Docker image - alpine id: push-alpine uses: docker/build-push-action@v7 with: context: . push: true file: deploy/Containerfile.alpine tags: | ${{ steps.meta-alpine.outputs.tags }} ghcr.io/sintan1729/${{ env.IMAGE_NAME }}:dev labels: ${{ steps.meta-alpine.outputs.labels }} platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/riscv64 annotations: ${{ steps.meta-alpine.outputs.annotations }} - name: Build and push Docker image - scratch id: push-scratch uses: docker/build-push-action@v7 with: context: . push: true file: deploy/Containerfile.scratch tags: ${{ steps.meta-scratch.outputs.tags }} labels: ${{ steps.meta-scratch.outputs.labels }} platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/riscv64 annotations: ${{ steps.meta-scratch.outputs.annotations }} # Attestation - name: Generate artifact attestation - alpine uses: actions/attest@v4 with: subject-name: sintan1729/${{ env.IMAGE_NAME }} subject-digest: ${{ steps.push-alpine.outputs.digest }} - name: Generate artifact attestation - scratch uses: actions/attest@v4 with: subject-name: sintan1729/${{ env.IMAGE_NAME }} subject-digest: ${{ steps.push-scratch.outputs.digest }} # Create a release with changelog - name: Generate a changelog uses: orhun/git-cliff-action@v4 id: git-cliff with: config: .github/cliff.toml args: --latest --strip header env: GITHUB_REPO: ${{ github.repository }} OUTPUT: CHANGELOG.md - name: Show the changelog run: cat CHANGELOG.md - name: Release uses: softprops/action-gh-release@v3 with: body_path: ${{ steps.git-cliff.outputs.changelog }} make_latest: true