name: Build Develop on: push: branches: - develop env: MIX_ENV: prod GH_TOKEN: ${{ github.token }} REGISTRY_IMAGE: wandererltd/community-edition concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true permissions: contents: write jobs: build: name: 🛠 Build runs-on: ubuntu-22.04 if: ${{ github.ref == 'refs/heads/develop' && github.event_name == 'push' }} permissions: checks: write contents: write packages: write attestations: write id-token: write pull-requests: write repository-projects: write strategy: matrix: otp: ["27"] elixir: ["1.17"] node-version: ["18.x"] outputs: commit_hash: ${{ steps.set-commit-develop.outputs.commit_hash }} steps: - name: Prepare run: | platform=${{ matrix.platform }} echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV - name: Setup Elixir uses: erlef/setup-beam@v1 with: otp-version: ${{matrix.otp}} elixir-version: ${{matrix.elixir}} # nix build would also work here because `todos` is the default package - name: ⬇️ Checkout repo uses: actions/checkout@v3 with: ssh-key: "${{ secrets.COMMIT_KEY }}" fetch-depth: 0 - name: 😅 Cache deps id: cache-deps uses: actions/cache@v4 env: cache-name: cache-elixir-deps with: path: | deps key: ${{ runner.os }}-mix-${{ matrix.elixir }}-${{ matrix.otp }}-${{ hashFiles('**/mix.lock') }} restore-keys: | ${{ runner.os }}-mix-${{ matrix.elixir }}-${{ matrix.otp }}- - name: 😅 Cache compiled build id: cache-build uses: actions/cache@v4 env: cache-name: cache-compiled-build with: path: | _build key: ${{ runner.os }}-build-${{ hashFiles('**/mix.lock') }}-${{ hashFiles( '**/lib/**/*.{ex,eex}', '**/config/*.exs', '**/mix.exs' ) }} restore-keys: | ${{ runner.os }}-build-${{ hashFiles('**/mix.lock') }}- ${{ runner.os }}-build- # Step: Download project dependencies. If unchanged, uses # the cached version. - name: 🌐 Install dependencies run: mix deps.get --only "prod" # Step: Compile the project treating any warnings as errors. # Customize this step if a different behavior is desired. - name: 🛠 Compiles without warnings if: steps.cache-build.outputs.cache-hit != 'true' run: mix compile - name: Set commit hash for develop id: set-commit-develop run: | echo "commit_hash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT docker: name: 🛠 Build Docker Images needs: build runs-on: ubuntu-22.04 permissions: checks: write contents: write packages: write attestations: write id-token: write pull-requests: write repository-projects: write strategy: fail-fast: false matrix: platform: - linux/amd64 - linux/arm64 steps: - name: Prepare run: | platform=${{ matrix.platform }} echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV - name: ⬇️ Checkout repo uses: actions/checkout@v3 with: ref: ${{ needs.build.outputs.commit_hash }} fetch-depth: 0 - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY_IMAGE }} - name: Set up QEMU uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Login to DockerHub uses: docker/login-action@v3 with: username: ${{ secrets.WANDERER_DOCKER_USER }} password: ${{ secrets.WANDERER_DOCKER_PASSWORD }} - name: Build and push id: build uses: docker/build-push-action@v6 with: push: true context: . file: ./Dockerfile cache-from: type=gha cache-to: type=gha,mode=max labels: ${{ steps.meta.outputs.labels }} platforms: ${{ matrix.platform }} outputs: type=image,"name=${{ env.REGISTRY_IMAGE }}",push-by-digest=true,name-canonical=true,push=true build-args: | MIX_ENV=prod BUILD_METADATA=${{ steps.meta.outputs.json }} - name: Export digest run: | mkdir -p /tmp/digests digest="${{ steps.build.outputs.digest }}" touch "/tmp/digests/${digest#sha256:}" - name: Upload digest uses: actions/upload-artifact@v4 with: name: digests-${{ env.PLATFORM_PAIR }} path: /tmp/digests/* if-no-files-found: error retention-days: 1 merge: runs-on: ubuntu-latest needs: - docker steps: - name: Download digests uses: actions/download-artifact@v4 with: path: /tmp/digests pattern: digests-* merge-multiple: true - name: Login to Docker Hub uses: docker/login-action@v3 with: username: ${{ secrets.WANDERER_DOCKER_USER }} password: ${{ secrets.WANDERER_DOCKER_PASSWORD }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Docker meta id: meta uses: docker/metadata-action@v5 with: images: | ${{ env.REGISTRY_IMAGE }} tags: | type=ref,event=branch type=ref,event=pr type=raw,value=develop,enable=${{ github.ref == 'refs/heads/develop' }} type=raw,value=develop-{{sha}},enable=${{ github.ref == 'refs/heads/develop' }} - name: Create manifest list and push working-directory: /tmp/digests run: | docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) - name: Inspect image run: | docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} notify: name: 🏷 Notify about develop release runs-on: ubuntu-22.04 needs: [docker, merge] steps: - name: Discord Webhook Action uses: tsickert/discord-webhook@v5.3.0 with: webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL_DEV }} content: | 📣 New develop release available 🚀 **Commit**: `${{ github.sha }}` **Status**: Development/Testing Release Docker image: `wandererltd/community-edition:develop` ⚠️ This is an unstable development release for testing purposes.