name: Monorepo Pipeline on: push: branches: - '**' tags: - 'v*' concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: prioritize: name: โšก Prioritize Release runs-on: docker container: image: catthehacker/ubuntu:act-latest steps: - name: ๐Ÿ›‘ Cancel Redundant Runs if: startsWith(github.ref, 'refs/tags/v') env: GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }} REPO: ${{ github.repository }} RUN_ID: ${{ github.run_id }} run: | echo "๐Ÿš€ Release detected. Cancelling non-tag runs..." # Get all runs for this repo RUNS=$(curl -s -H "Authorization: token $GITEA_TOKEN" "https://git.infra.mintel.me/api/v1/repos/$REPO/actions/runs") # Iterate and cancel in_progress/queued non-tag runs echo "$RUNS" | jq -c '.workflow_runs[] | select(.status == "in_progress" or .status == "queued") | select(.id | tostring != "'$RUN_ID'") | select(.event != "push" or .ref | contains("refs/tags/v") | not)' | while read run; do ID=$(echo "$run" | jq -r '.id') DESC=$(echo "$run" | jq -r '.display_title') echo "๐Ÿ›‘ Cancelling redundant run $ID ($DESC)..." curl -X POST -s -H "Authorization: token $GITEA_TOKEN" "https://git.infra.mintel.me/api/v1/repos/$REPO/actions/runs/$ID/cancel" done lint: name: ๐Ÿงน Lint needs: prioritize if: always() && !cancelled() && (needs.prioritize.result == 'success' || needs.prioritize.result == 'skipped') runs-on: docker container: image: catthehacker/ubuntu:act-latest env: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} steps: - name: Checkout uses: actions/checkout@v4 - name: Set up Environment uses: pnpm/action-setup@v4 with: version: 10 run_install: | - recursive: true args: [--frozen-lockfile, --prefer-offline] - name: Set up Node.js uses: actions/setup-node@v4 with: node_version: 20 cache: 'pnpm' - name: Lint run: pnpm lint test: name: ๐Ÿงช Test needs: prioritize if: always() && !cancelled() && (needs.prioritize.result == 'success' || needs.prioritize.result == 'skipped') runs-on: docker container: image: catthehacker/ubuntu:act-latest env: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} steps: - name: Checkout uses: actions/checkout@v4 - name: Set up Environment uses: pnpm/action-setup@v4 with: version: 10 run_install: | - recursive: true args: [--frozen-lockfile, --prefer-offline] - name: Set up Node.js uses: actions/setup-node@v4 with: node_version: 20 cache: 'pnpm' - name: Test run: pnpm test build: name: ๐Ÿ—๏ธ Build needs: prioritize if: always() && !cancelled() && (needs.prioritize.result == 'success' || needs.prioritize.result == 'skipped') runs-on: docker container: image: catthehacker/ubuntu:act-latest env: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} steps: - name: Checkout uses: actions/checkout@v4 - name: Set up Environment uses: pnpm/action-setup@v4 with: version: 10 run_install: | - recursive: true args: [--frozen-lockfile, --prefer-offline] - name: Set up Node.js uses: actions/setup-node@v4 with: node_version: 20 cache: 'pnpm' - name: Build run: pnpm build release: name: ๐Ÿš€ Release needs: [lint, test, build] if: startsWith(github.ref, 'refs/tags/v') runs-on: docker container: image: catthehacker/ubuntu:act-latest env: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up Environment uses: pnpm/action-setup@v4 with: version: 10 run_install: | - recursive: true args: [--frozen-lockfile, --prefer-offline] - name: Set up Node.js uses: actions/setup-node@v4 with: node_version: 20 cache: 'pnpm' - name: ๐Ÿท๏ธ Sync Versions (if Tagged) run: pnpm sync-versions - name: ๐Ÿท๏ธ Release Packages (Tag-Driven) run: | echo "๐Ÿท๏ธ Tag detected [${{ github.ref_name }}], performing sync release..." pnpm release:tag build-images: name: ๐Ÿณ Build ${{ matrix.name }} needs: [lint, test, build] if: startsWith(github.ref, 'refs/tags/v') runs-on: docker container: image: catthehacker/ubuntu:act-latest strategy: fail-fast: false matrix: include: - image: nextjs file: packages/infra/docker/Dockerfile.nextjs name: Build-Base - image: runtime file: packages/infra/docker/Dockerfile.runtime name: Production Runtime - image: gatekeeper file: packages/infra/docker/Dockerfile.gatekeeper name: Gatekeeper (Product) - image: directus file: packages/infra/docker/Dockerfile.directus name: Directus (Base) steps: - name: Checkout uses: actions/checkout@v4 - name: ๐Ÿณ Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: ๐Ÿ” Registry Login uses: docker/login-action@v3 with: registry: registry.infra.mintel.me username: ${{ secrets.REGISTRY_USER }} password: ${{ secrets.REGISTRY_PASS }} - name: ๐Ÿ—๏ธ Build & Push ${{ matrix.name }} uses: docker/build-push-action@v5 with: context: . file: ${{ matrix.file }} platforms: linux/arm64 pull: true push: true secrets: | NPM_TOKEN=${{ secrets.NPM_TOKEN }} tags: | registry.infra.mintel.me/mintel/${{ matrix.image }}:${{ github.ref_name }} registry.infra.mintel.me/mintel/${{ matrix.image }}:latest cache-from: type=registry,ref=registry.infra.mintel.me/mintel/${{ matrix.image }}:buildcache cache-to: type=registry,ref=registry.infra.mintel.me/mintel/${{ matrix.image }}:buildcache,mode=max