|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + pull_request: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + |
| 10 | +jobs: |
| 11 | + lint: |
| 12 | + name: Lint |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Checkout |
| 16 | + uses: actions/checkout@v4 |
| 17 | + |
| 18 | + - name: Setup Biome |
| 19 | + uses: biomejs/setup-biome@v2 |
| 20 | + |
| 21 | + - name: Run Biome |
| 22 | + run: biome ci . |
| 23 | + |
| 24 | + check-yarn-lock: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + steps: |
| 27 | + - name: Checkout repository |
| 28 | + uses: actions/checkout@v4 |
| 29 | + |
| 30 | + - name: Set up Node.js |
| 31 | + uses: actions/setup-node@v4 |
| 32 | + with: |
| 33 | + node-version: "lts/*" |
| 34 | + cache: "yarn" |
| 35 | + |
| 36 | + - name: Check yarn.lock |
| 37 | + run: yarn install --frozen-lockfile |
| 38 | + |
| 39 | + build-test-push: |
| 40 | + name: Build, Test and Push |
| 41 | + environment: staging |
| 42 | + runs-on: ubuntu-latest |
| 43 | + needs: [lint, check-yarn-lock] |
| 44 | + outputs: |
| 45 | + migrations_docker_version: ${{ steps.migrations-docker-metadata.outputs.version }} |
| 46 | + activitypub_docker_version: ${{ steps.activitypub-docker-metadata.outputs.version }} |
| 47 | + steps: |
| 48 | + - name: "Checkout" |
| 49 | + uses: actions/checkout@v4 |
| 50 | + |
| 51 | + - name: ActivityPub Docker meta |
| 52 | + id: activitypub-docker-metadata |
| 53 | + uses: docker/metadata-action@v5 |
| 54 | + with: |
| 55 | + images: | |
| 56 | + europe-docker.pkg.dev/ghost-activitypub/activitypub/activitypub |
| 57 | + tags: | |
| 58 | + ${{ github.ref == 'refs/heads/main' && 'type=edge,branch=main' || '' }} |
| 59 | + ${{ github.event_name == 'pull_request' && format('type=raw,value=pr-{0}', github.event.pull_request.number) || '' }} |
| 60 | + type=raw,value=${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} |
| 61 | + type=semver,pattern={{version}} |
| 62 | + type=semver,pattern={{major}}.{{minor}} |
| 63 | + type=semver,pattern={{major}} |
| 64 | + type=sha,priority=1100 |
| 65 | +
|
| 66 | + - name: Migrations Docker meta |
| 67 | + id: migrations-docker-metadata |
| 68 | + uses: docker/metadata-action@v5 |
| 69 | + with: |
| 70 | + images: | |
| 71 | + europe-docker.pkg.dev/ghost-activitypub/activitypub/migrations |
| 72 | + tags: | |
| 73 | + ${{ github.ref == 'refs/heads/main' && 'type=edge,branch=main' || '' }} |
| 74 | + ${{ github.event_name == 'pull_request' && format('type=raw,value=pr-{0}', github.event.pull_request.number) || '' }} |
| 75 | + type=raw,value=${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} |
| 76 | + type=semver,pattern={{version}} |
| 77 | + type=semver,pattern={{major}}.{{minor}} |
| 78 | + type=semver,pattern={{major}} |
| 79 | + type=sha,priority=1100 |
| 80 | +
|
| 81 | + - name: "Build Docker Image for ActivityPub" |
| 82 | + uses: docker/build-push-action@v6 |
| 83 | + with: |
| 84 | + context: . |
| 85 | + load: true |
| 86 | + tags: ${{ steps.activitypub-docker-metadata.outputs.tags }} |
| 87 | + |
| 88 | + - name: "Build Docker Image for Migrations" |
| 89 | + uses: docker/build-push-action@v6 |
| 90 | + with: |
| 91 | + context: migrate |
| 92 | + load: true |
| 93 | + tags: ${{ steps.migrations-docker-metadata.outputs.tags }} |
| 94 | + |
| 95 | + # - name: "Run Tests" |
| 96 | + # run: yarn test |
| 97 | + |
| 98 | + - name: "Login to GCP Artifact Registry" |
| 99 | + uses: docker/login-action@v3 |
| 100 | + with: |
| 101 | + registry: europe-docker.pkg.dev |
| 102 | + username: _json_key |
| 103 | + password: ${{ secrets.GCP_DEPLOYER_SERVICE_ACCOUNT_KEY }} |
| 104 | + |
| 105 | + - name: "Push ActivityPub Docker Image" |
| 106 | + uses: docker/build-push-action@v6 |
| 107 | + with: |
| 108 | + context: . |
| 109 | + push: true |
| 110 | + tags: ${{ steps.activitypub-docker-metadata.outputs.tags }} |
| 111 | + |
| 112 | + - name: "Push Migrations Docker Image" |
| 113 | + uses: docker/build-push-action@v6 |
| 114 | + with: |
| 115 | + context: migrate |
| 116 | + push: true |
| 117 | + tags: ${{ steps.migrations-docker-metadata.outputs.tags }} |
| 118 | + |
| 119 | + - uses: tryghost/actions/actions/slack-build@main |
| 120 | + if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 121 | + with: |
| 122 | + status: ${{ job.status }} |
| 123 | + env: |
| 124 | + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |
| 125 | + |
| 126 | + deploy-staging: |
| 127 | + if: github.ref == 'refs/heads/main' |
| 128 | + name: (staging) Deploy |
| 129 | + environment: staging |
| 130 | + runs-on: ubuntu-latest |
| 131 | + needs: [build-test-push] |
| 132 | + strategy: |
| 133 | + matrix: |
| 134 | + region: [europe-west4, europe-west3] |
| 135 | + include: |
| 136 | + - region: europe-west4 |
| 137 | + region_name: netherlands |
| 138 | + - region: europe-west3 |
| 139 | + region_name: frankfurt |
| 140 | + steps: |
| 141 | + - name: "Auth with Google Cloud" |
| 142 | + uses: "google-github-actions/auth@v2" |
| 143 | + with: |
| 144 | + credentials_json: ${{ secrets.GCP_DEPLOYER_SERVICE_ACCOUNT_KEY }} |
| 145 | + |
| 146 | + - name: "Deploy Migrations to Cloud Run" |
| 147 | + if: ${{ matrix.region == 'europe-west4' }} |
| 148 | + uses: "google-github-actions/deploy-cloudrun@v2" |
| 149 | + with: |
| 150 | + image: europe-docker.pkg.dev/ghost-activitypub/activitypub/migrations:${{ needs.build-test-push.outputs.migrations_docker_version }} |
| 151 | + region: ${{ matrix.region }} |
| 152 | + job: stg-${{ matrix.region_name }}-activitypub-migrations |
| 153 | + flags: "--wait --execute-now" |
| 154 | + skip_default_labels: true |
| 155 | + labels: |- |
| 156 | + commit-sha=${{ github.sha }} |
| 157 | +
|
| 158 | + - name: "Deploy ActivityPub Queue to Cloud Run" |
| 159 | + uses: "google-github-actions/deploy-cloudrun@v2" |
| 160 | + with: |
| 161 | + image: europe-docker.pkg.dev/ghost-activitypub/activitypub/activitypub:${{ needs.build-test-push.outputs.activitypub_docker_version }} |
| 162 | + region: ${{ matrix.region }} |
| 163 | + service: stg-${{ matrix.region_name }}-activitypub-queue |
| 164 | + skip_default_labels: true |
| 165 | + labels: |- |
| 166 | + commit-sha=${{ github.sha }} |
| 167 | +
|
| 168 | + - name: "Deploy ActivityPub API to Cloud Run" |
| 169 | + uses: "google-github-actions/deploy-cloudrun@v2" |
| 170 | + with: |
| 171 | + image: europe-docker.pkg.dev/ghost-activitypub/activitypub/activitypub:${{ needs.build-test-push.outputs.activitypub_docker_version }} |
| 172 | + region: ${{ matrix.region }} |
| 173 | + service: stg-${{ matrix.region_name }}-activitypub-api |
| 174 | + skip_default_labels: true |
| 175 | + labels: |- |
| 176 | + commit-sha=${{ github.sha }} |
| 177 | +
|
| 178 | + deploy-production: |
| 179 | + if: github.ref == 'refs/heads/main' |
| 180 | + name: (production) Deploy |
| 181 | + environment: production |
| 182 | + runs-on: ubuntu-latest |
| 183 | + needs: [build-test-push, deploy-staging] |
| 184 | + strategy: |
| 185 | + matrix: |
| 186 | + region: [europe-west4, europe-west3] |
| 187 | + include: |
| 188 | + - region: europe-west4 |
| 189 | + region_name: netherlands |
| 190 | + - region: europe-west3 |
| 191 | + region_name: frankfurt |
| 192 | + steps: |
| 193 | + - name: "Auth with Google Cloud" |
| 194 | + uses: "google-github-actions/auth@v2" |
| 195 | + with: |
| 196 | + credentials_json: ${{ secrets.GCP_DEPLOYER_SERVICE_ACCOUNT_KEY }} |
| 197 | + |
| 198 | + - name: "Deploy Migrations to Cloud Run" |
| 199 | + if: ${{ matrix.region == 'europe-west4' }} |
| 200 | + uses: "google-github-actions/deploy-cloudrun@v2" |
| 201 | + with: |
| 202 | + image: europe-docker.pkg.dev/ghost-activitypub/activitypub/migrations:${{ needs.build-test-push.outputs.migrations_docker_version }} |
| 203 | + region: ${{ matrix.region }} |
| 204 | + job: prd-${{ matrix.region_name }}-activitypub-migrations |
| 205 | + flags: "--wait --execute-now" |
| 206 | + skip_default_labels: true |
| 207 | + labels: |- |
| 208 | + commit-sha=${{ github.sha }} |
| 209 | +
|
| 210 | + - name: "Deploy ActivityPub Queue to Cloud Run" |
| 211 | + uses: "google-github-actions/deploy-cloudrun@v2" |
| 212 | + with: |
| 213 | + image: europe-docker.pkg.dev/ghost-activitypub/activitypub/activitypub:${{ needs.build-test-push.outputs.activitypub_docker_version }} |
| 214 | + region: ${{ matrix.region }} |
| 215 | + service: prd-${{ matrix.region_name }}-activitypub-queue |
| 216 | + skip_default_labels: true |
| 217 | + labels: |- |
| 218 | + commit-sha=${{ github.sha }} |
| 219 | +
|
| 220 | + - name: "Deploy ActivityPub API to Cloud Run" |
| 221 | + uses: "google-github-actions/deploy-cloudrun@v2" |
| 222 | + with: |
| 223 | + image: europe-docker.pkg.dev/ghost-activitypub/activitypub/activitypub:${{ needs.build-test-push.outputs.activitypub_docker_version }} |
| 224 | + region: ${{ matrix.region }} |
| 225 | + service: prd-${{ matrix.region_name }}-activitypub-api |
| 226 | + skip_default_labels: true |
| 227 | + labels: |- |
| 228 | + commit-sha=${{ github.sha }} |
| 229 | +
|
| 230 | + - uses: tryghost/actions/actions/slack-build@main |
| 231 | + if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 232 | + with: |
| 233 | + status: ${{ job.status }} |
| 234 | + env: |
| 235 | + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |
0 commit comments