Test and Docker Release #98
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
| name: Test and Docker Release | |
| on: | |
| push: | |
| tags: | |
| - "*" | |
| branches: ["main"] | |
| paths: ["actix/**", "resources/**"] | |
| workflow_dispatch: | |
| env: | |
| CARGO_TERM_COLOR: always | |
| IMAGE_NAME: chhoto-url | |
| jobs: | |
| build: | |
| name: Build and Test - ${{ matrix.platform.os-name }} | |
| 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 | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| # Build the binaries and upload | |
| - name: Build binary and test | |
| uses: houseabsolute/actions-rust-cross@v1 | |
| with: | |
| command: both | |
| target: ${{ matrix.platform.target }} | |
| args: "--locked --release --manifest-path=actix/Cargo.toml" | |
| rust-cache-parameters: '{"workspaces":"actix -> target"}' | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.platform.target }} | |
| path: ./actix/target/${{ matrix.platform.target }}/release/${{ env.IMAGE_NAME }} | |
| retention-days: 1 | |
| if-no-files-found: error | |
| merge: | |
| name: Docker Release | |
| 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@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| - name: Move stuff around and fix permissions | |
| run: | | |
| for f in *-unknown-linux-musl* | |
| do | |
| mkdir -p actix/target/$f/release | |
| mv $f/chhoto-url actix/target/$f/release/ | |
| chmod +x actix/target/$f/release/chhoto-url | |
| done | |
| - name: Minify resources for release | |
| if: github.ref_type == 'tag' | |
| run: | | |
| mv resources/ resources-original/ | |
| sudo apt update | |
| sudo apt install minify | |
| minify -rs resources-original/ -o resources/ | |
| - name: Display current directory structure | |
| run: ls -R | |
| - name: Log in to the Docker Hub | |
| uses: docker/login-action@v3 | |
| if: github.ref_type == 'tag' | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Log in to the Container registry | |
| uses: docker/login-action@v3 | |
| 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@v5 | |
| if: github.ref_type == 'tag' | |
| env: | |
| DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index | |
| with: | |
| images: | | |
| sintan1729/${{ env.IMAGE_NAME }} | |
| ghcr.io/sintan1729/${{ env.IMAGE_NAME }} | |
| flavor: | | |
| suffix=-alpine,onlatest=true | |
| tags: | | |
| type=semver,pattern={{major}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=semver,pattern={{version}} | |
| - name: Extract metadata (tags, labels) for Docker - scratch | |
| id: meta-scratch | |
| uses: docker/metadata-action@v5 | |
| if: github.ref_type == 'tag' | |
| 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}} | |
| - name: Extract metadata (tags, labels) for Docker - dev | |
| id: meta-dev | |
| uses: docker/metadata-action@v5 | |
| if: github.ref_type != 'tag' | |
| 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@v3 | |
| - name: Build and push Docker image - alpine | |
| id: push-alpine | |
| uses: docker/build-push-action@v6 | |
| if: github.ref_type == 'tag' | |
| with: | |
| context: . | |
| push: true | |
| file: Dockerfile.alpine | |
| tags: ${{ steps.meta-alpine.outputs.tags }} | |
| labels: ${{ steps.meta-alpine.outputs.labels }} | |
| platforms: linux/amd64,linux/arm64,linux/arm/v7 | |
| annotations: ${{ steps.meta-alpine.outputs.annotations }} | |
| - name: Build and push Docker image - scratch | |
| id: push-scratch | |
| uses: docker/build-push-action@v6 | |
| if: github.ref_type == 'tag' | |
| with: | |
| context: . | |
| push: true | |
| file: Dockerfile.scratch | |
| tags: ${{ steps.meta-scratch.outputs.tags }} | |
| labels: ${{ steps.meta-scratch.outputs.labels }} | |
| platforms: linux/amd64,linux/arm64,linux/arm/v7 | |
| annotations: ${{ steps.meta-scratch.outputs.annotations }} | |
| - name: Build and push Docker image - dev | |
| id: push-dev | |
| uses: docker/build-push-action@v6 | |
| if: github.ref_type != 'tag' | |
| with: | |
| context: . | |
| push: true | |
| file: Dockerfile.alpine | |
| tags: ${{ steps.meta-dev.outputs.tags }} | |
| labels: ${{ steps.meta-dev.outputs.labels }} | |
| platforms: linux/amd64,linux/arm64,linux/arm/v7 | |
| # Attestation | |
| - name: Generate artifact attestation - alpine | |
| uses: actions/attest-build-provenance@v2 | |
| if: github.ref_type == 'tag' | |
| with: | |
| subject-name: sintan1729/${{ env.IMAGE_NAME }} | |
| subject-digest: ${{ steps.push-alpine.outputs.digest }} | |
| - name: Generate artifact attestation - scratch | |
| uses: actions/attest-build-provenance@v2 | |
| if: github.ref_type == 'tag' | |
| with: | |
| subject-name: sintan1729/${{ env.IMAGE_NAME }} | |
| subject-digest: ${{ steps.push-scratch.outputs.digest }} | |
| - name: Generate artifact attestation - dev | |
| uses: actions/attest-build-provenance@v2 | |
| if: github.ref_type != 'tag' | |
| with: | |
| subject-name: sintan1729/${{ env.IMAGE_NAME }} | |
| subject-digest: ${{ steps.push-dev.outputs.digest }} | |
| # Create a release with changelog | |
| - name: Generate a changelog | |
| uses: orhun/git-cliff-action@v4 | |
| if: github.ref_type == 'tag' | |
| id: git-cliff | |
| with: | |
| config: .github/cliff.toml | |
| args: --latest --strip header | |
| env: | |
| GITHUB_REPO: ${{ github.repository }} | |
| OUTPUT: CHANGELOG.md | |
| - name: Show the changelog | |
| if: github.ref_type == 'tag' | |
| run: cat CHANGELOG.md | |
| - name: Release | |
| uses: softprops/action-gh-release@v2 | |
| if: github.ref_type == 'tag' | |
| with: | |
| body_path: ${{ steps.git-cliff.outputs.changelog }} | |
| make_latest: true |