CI/CD #12229
This file contains 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: ci | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
schedule: | |
- cron: "0 */2 * * *" | |
env: | |
DISCORD_DEPLOY_WEBHOOK_URL: ${{ secrets.DISCORD_DEPLOY_WEBHOOK_URL }} | |
DISCORD_CHANGELOG_WEBHOOK_URL: ${{ secrets.DISCORD_CHANGELOG_WEBHOOK_URL }} | |
EDITOR_BACKEND_URL: ${{ secrets.EDITOR_BACKEND_URL }} | |
jobs: | |
setup: | |
runs-on: ubuntu-22.04 | |
outputs: | |
workflow_id: ${{ steps.generate-uuid.outputs.uuid }} | |
steps: | |
- name: Checkout 🛎 | |
uses: actions/checkout@master | |
- name: Setup Node ⬢ | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
cache: "yarn" | |
- name: Cache node modules 🗃 | |
id: cache-nodemodules | |
uses: actions/cache@v3 | |
with: | |
# npm packages are cached in node_modules | |
# npm also provides a local cache in .npm | |
# Cypress binary is stored in ~/.cache | |
path: | | |
node_modules | |
~/.npm | |
~/.cache | |
key: ${{ runner.os }}-node-modules-build-${{ hashFiles('**/yarn.lock') }} | |
- name: Install Node Modules 📦 | |
if: steps.cache-nodemodules.outputs.cache-hit != 'true' | |
run: yarn install --frozen-lockfile | |
- name: Create Workflow ID 🆔 | |
id: generate-uuid | |
run: yarn run workflow:create-workflow-id | |
- name: Cache Site Data ⏬ | |
id: cache-downloaded-data | |
uses: actions/cache@v3 | |
with: | |
path: | | |
autocomplete-data | |
external-data | |
frontend/public/api/combo-data.json | |
frontend/public/changelog.json | |
frontend/out/ | |
frontend/.next/ | |
key: ${{ runner.os }}-download-data-${{ steps.generate-uuid.outputs.uuid }} | |
- name: Download Data ⬇️ | |
if: steps.cache-downloaded-data.outputs.cache-hit != 'true' | |
env: | |
NODE_ENV: production | |
run: yarn run download-data | |
- name: Build Frontend Site 🏗️ | |
if: steps.cache-downloaded-data.outputs.cache-hit != 'true' | |
run: yarn run build | |
env: | |
NODE_ENV: production | |
linter: | |
runs-on: ubuntu-22.04 | |
needs: setup | |
steps: | |
- name: Checkout 🛎️ | |
uses: actions/checkout@v3 | |
- name: Setup Node ⬢ | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
cache: "yarn" | |
- name: Restore node modules from cache 📦 | |
id: cache-nodemodules | |
uses: actions/cache@v3 | |
with: | |
path: | | |
node_modules | |
~/.npm | |
~/.cache | |
key: ${{ runner.os }}-node-modules-build-${{ hashFiles('**/yarn.lock') }} | |
- name: Install 📦 | |
if: steps.cache-nodemodules.outputs.cache-hit != 'true' | |
run: yarn install --frozen-lockfile | |
- name: Run linter 👀 | |
run: yarn run lint | |
integration-tests: | |
runs-on: ubuntu-22.04 | |
needs: setup | |
steps: | |
- name: Checkout 🛎️ | |
uses: actions/checkout@v3 | |
- name: Setup Node ⬢ | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
cache: "yarn" | |
- name: Restore node modules from cache 📦 | |
id: cache-nodemodules | |
uses: actions/cache@v3 | |
with: | |
path: | | |
node_modules | |
~/.npm | |
~/.cache | |
key: ${{ runner.os }}-node-modules-build-${{ hashFiles('**/yarn.lock') }} | |
- name: Install 📦 | |
if: steps.cache-nodemodules.outputs.cache-hit != 'true' | |
run: yarn install --frozen-lockfile | |
- name: Restore Site Data ⏬ | |
id: cache-downloaded-data | |
uses: actions/cache@v3 | |
with: | |
path: | | |
autocomplete-data | |
external-data | |
frontend/public/api/combo-data.json | |
frontend/public/changelog.json | |
frontend/out/ | |
frontend/.next/ | |
key: ${{ runner.os }}-download-data-${{ needs.setup.outputs.workflow_id }} | |
- name: Check Site Cache ⬇️ | |
if: steps.cache-downloaded-data.outputs.cache-hit != 'true' | |
run: echo "Site cache failed"; exit 1; | |
- name: Run Integration tests 💻 | |
run: yarn run test:integration | |
env: | |
NODE_ENV: development | |
changelog_check: | |
# only run this check from the main branch | |
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && github.repository_owner == 'SpaceCowMedia' | |
runs-on: ubuntu-22.04 | |
needs: setup | |
concurrency: production_deploy | |
outputs: | |
should_deploy: ${{ steps.changelog_result.outputs.should_deploy }} | |
deploy_reason: ${{ steps.changelog_result.outputs.deploy_reason }} | |
steps: | |
- name: Checkout 🛎️ | |
uses: actions/checkout@v3 | |
- name: Setup Node ⬢ | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
cache: "yarn" | |
- name: Restore node modules from cache 📦 | |
id: cache-nodemodules | |
uses: actions/cache@v3 | |
with: | |
path: | | |
node_modules | |
~/.npm | |
~/.cache | |
key: ${{ runner.os }}-node-modules-build-${{ hashFiles('**/yarn.lock') }} | |
- name: Install 📦 | |
if: steps.cache-nodemodules.outputs.cache-hit != 'true' | |
run: yarn install --frozen-lockfile | |
- name: Restore Site Data ⏬ | |
id: cache-downloaded-data | |
uses: actions/cache@v3 | |
with: | |
path: | | |
autocomplete-data | |
external-data | |
frontend/public/api/combo-data.json | |
frontend/public/changelog.json | |
frontend/out/ | |
frontend/.next/ | |
key: ${{ runner.os }}-download-data-${{ needs.setup.outputs.workflow_id }} | |
- name: Check Site Cache ⬇️ | |
if: steps.cache-downloaded-data.outputs.cache-hit != 'true' | |
run: echo "Site cache failed"; exit 1; | |
- name: Compare Changelog 🪵 | |
id: changelog_result | |
run: yarn run check-changelog | |
deploy: | |
# only deploy from the main branch | |
# and the changelog check indicates | |
# that there are changes to deploy | |
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && github.repository_owner == 'SpaceCowMedia' && needs.changelog_check.outputs.should_deploy == 'YES' | |
concurrency: production_deploy | |
runs-on: ubuntu-22.04 | |
needs: [setup, linter, integration-tests, changelog_check] | |
steps: | |
- name: Checkout 🛎️ | |
uses: actions/checkout@v3 | |
- name: Setup Node ⬢ | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
cache: "yarn" | |
- name: Restore node modules from cache 📦 | |
id: cache-nodemodules | |
uses: actions/cache@v3 | |
with: | |
path: | | |
node_modules | |
~/.npm | |
~/.cache | |
key: ${{ runner.os }}-node-modules-build-${{ hashFiles('**/yarn.lock') }} | |
- name: Install 📦 | |
if: steps.cache-nodemodules.outputs.cache-hit != 'true' | |
run: yarn install --frozen-lockfile | |
- name: Restore Site Data ⏬ | |
id: cache-downloaded-data | |
uses: actions/cache@v3 | |
with: | |
path: | | |
autocomplete-data | |
external-data | |
frontend/public/api/combo-data.json | |
frontend/public/changelog.json | |
frontend/out/ | |
frontend/.next/ | |
key: ${{ runner.os }}-download-data-${{ needs.setup.outputs.workflow_id }} | |
- name: Check Site Cache ⬇️ | |
if: steps.cache-downloaded-data.outputs.cache-hit != 'true' | |
run: echo "Site cache failed"; exit 1; | |
- name: Configure AWS Credentials ㊙️ | |
uses: aws-actions/configure-aws-credentials@v1-node16 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: us-east-1 | |
- name: Deploy to S3 🛫 | |
run: aws s3 sync ./frontend/out/ s3://commanderspellbook.com --delete | |
- name: Bust Cloudfront Cache 👥 | |
env: | |
AWS_MAX_ATTEMPTS: 8 | |
run: aws cloudfront create-invalidation --distribution-id EOJD6575ATAH3 --paths "/*" | |
- name: Send Deploy Failed Notification ✉️ | |
if: ${{ failure() }} | |
run: yarn run discord-webhook:failed-deploy | |
cancel-deploy-notification: | |
# only send a message about cancelling deploy from the main branch | |
# and the changelog check indicates that there are no changes to deploy | |
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && github.repository_owner == 'SpaceCowMedia' && needs.changelog_check.outputs.should_deploy == 'NO' | |
runs-on: ubuntu-22.04 | |
needs: [setup, changelog_check] | |
steps: | |
- name: Checkout 🛎️ | |
uses: actions/checkout@v3 | |
- name: Setup Node ⬢ | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
cache: "yarn" | |
- name: Restore node modules from cache 📦 | |
id: cache-nodemodules | |
uses: actions/cache@v3 | |
with: | |
path: | | |
node_modules | |
~/.npm | |
~/.cache | |
key: ${{ runner.os }}-node-modules-build-${{ hashFiles('**/yarn.lock') }} | |
- name: Install 📦 | |
if: steps.cache-nodemodules.outputs.cache-hit != 'true' | |
run: yarn install --frozen-lockfile | |
- name: Send deploy cancelled notification ✉️ | |
run: yarn run discord-webhook:cancel-deploy | |
send-start-deploy-notification: | |
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && github.repository_owner == 'SpaceCowMedia' && needs.changelog_check.outputs.should_deploy == 'YES' | |
runs-on: ubuntu-22.04 | |
needs: [setup, linter, integration-tests, changelog_check] | |
steps: | |
- name: Checkout 🛎️ | |
uses: actions/checkout@v3 | |
- name: Setup Node ⬢ | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
cache: "yarn" | |
- name: Restore node modules from cache 📦 | |
id: cache-nodemodules | |
uses: actions/cache@v3 | |
with: | |
path: | | |
node_modules | |
~/.npm | |
~/.cache | |
key: ${{ runner.os }}-node-modules-build-${{ hashFiles('**/yarn.lock') }} | |
- name: Install 📦 | |
if: steps.cache-nodemodules.outputs.cache-hit != 'true' | |
run: yarn install --frozen-lockfile | |
- name: Send Deploy Start Notification ✉️ | |
run: yarn run discord-webhook:start-deploy | |
finish-deploy-notification: | |
runs-on: ubuntu-22.04 | |
needs: [setup, changelog_check, deploy] | |
steps: | |
- name: Checkout 🛎️ | |
uses: actions/checkout@v3 | |
- name: Setup Node ⬢ | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
cache: "yarn" | |
- name: Restore node modules from cache 📦 | |
id: cache-nodemodules | |
uses: actions/cache@v3 | |
with: | |
path: | | |
node_modules | |
~/.npm | |
~/.cache | |
key: ${{ runner.os }}-node-modules-build-${{ hashFiles('**/yarn.lock') }} | |
- name: Install 📦 | |
if: steps.cache-nodemodules.outputs.cache-hit != 'true' | |
run: yarn install --frozen-lockfile | |
- name: Restore Site Data ⏬ | |
id: cache-downloaded-data | |
uses: actions/cache@v3 | |
with: | |
path: | | |
autocomplete-data | |
external-data | |
frontend/public/api/combo-data.json | |
frontend/public/changelog.json | |
frontend/out/ | |
frontend/.next/ | |
key: ${{ runner.os }}-download-data-${{ needs.setup.outputs.workflow_id }} | |
- name: Check Site Cache ⬇️ | |
if: steps.cache-downloaded-data.outputs.cache-hit != 'true' | |
run: echo "Site cache failed"; exit 1; | |
- name: Send deploy succeeded notification ✉️ | |
env: | |
DEPLOY_REASON: ${{needs.changelog_check.outputs.deploy_reason}} | |
run: yarn run discord-webhook:finish-deploy |