Skip to content

Commit

Permalink
Start work to set up an automated staging deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Aug 19, 2024
1 parent 03378f9 commit 1db0075
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: CI
on: [workflow_dispatch]
on: [push, workflow_dispatch]
jobs:
build:
name: Build & test
Expand All @@ -10,11 +10,9 @@ jobs:
# Install Node 14
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 20.11.1
cache: 'npm'

- run: npm install -g [email protected]

# Install & build & test:
- run: npm ci

Expand All @@ -24,30 +22,34 @@ jobs:
run: npm run build
env:
NODE_ENV: development
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Build with secrets for production, on push only:
- name: Build for production
if: github.event_name == 'push'
run: npm run build
env:
NODE_ENV: production
GATSBY_POSTHOG_KEY: ${{ secrets.GATSBY_POSTHOG_KEY }}
NEXT_PUBLIC_POSTHOG_KEY: ${{ vars.POSTHOG_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/upload-artifact@v4
with:
name: public
path: public/*
name: out
path: out/*
if-no-files-found: error

- uses: actions/upload-artifact@v4
with:
name: rss
path: public/rss.xml
path: out/rss.xml
if-no-files-found: error

check-blog-changes:
name: Check for new blog posts to announce
if: github.event_name == 'push'
if: false
# TODO: Put back to `github.event_name == 'push' && github.ref == 'refs/heads/main'` after
# the big site switchover is done, with some careful testing
runs-on: ubuntu-latest
needs: build
outputs:
Expand Down Expand Up @@ -102,8 +104,8 @@ jobs:

- uses: actions/download-artifact@v4
with:
name: public
path: public
name: out
path: out

- uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
Expand All @@ -119,8 +121,9 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
images: httptoolkit/website
tags: |
type=raw,value=prod,enable={{is_default_branch}}
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=prod,enable=${{ github.ref == 'refs/heads/main' }}
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=raw,value=staging,enable=${{ github.ref == 'refs/heads/next' }}
type=sha
- name: Publish to Docker Hub
Expand All @@ -132,8 +135,8 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}

publish-scaleway:
name: Deploy to Scaleway
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
name: Deploy to Scaleway ${{ vars.GHA_DEPLOY_ENV_NAME }}
if: github.event_name == 'push' && vars.GHA_DEPLOY_ENV_NAME
environment: production
runs-on: ubuntu-latest
needs: publish-docker
Expand All @@ -148,13 +151,15 @@ jobs:

- name: Redeploy failover container
uses: thibaultchazal/scaleway-serverless-container-deploy-action@0d290edda0c3359e51442bd8bf730eafef4e290f
if: ${{ vars.SCW_FAILOVER_API_CONTAINER_ID }}
with:
container_id: ${{ vars.SCW_FAILOVER_API_CONTAINER_ID }}
region: ${{ vars.SCW_FAILOVER_API_CONTAINER_REGION }}
secret_key: ${{ secrets.SCW_SECRET_KEY }}
registry_image_url: "registry.hub.docker.com/httptoolkit/website:prod"

- name: Flush CDN cache
if: ${{ vars.BUNNY_PULL_ZONE_ID }}
run: |
# Wait a little - the reploy command doesn't wait for the container to start up
sleep 30
Expand All @@ -164,7 +169,7 @@ jobs:
--url https://api.bunny.net/pullzone/$PULL_ZONE_ID/purgeCache \
--header "AccessKey: $BUNNY_SITE_API_KEY"
env:
PULL_ZONE_ID: 960393
PULL_ZONE_ID: ${{ vars.BUNNY_PULL_ZONE_ID }}
BUNNY_SITE_API_KEY: ${{ secrets.BUNNY_SITE_API_KEY }}

announce-blog-changes:
Expand Down

0 comments on commit 1db0075

Please sign in to comment.