Skip to content

Commit

Permalink
Copy array before sorting to avoid exception
Browse files Browse the repository at this point in the history
  • Loading branch information
lmcnulty committed Mar 29, 2024
2 parents 85188da + 61b5608 commit e86db3b
Show file tree
Hide file tree
Showing 174 changed files with 7,322 additions and 1,360 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/cache-modifier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Cache Modifier

on:
workflow_call:
inputs:
skip-cache:
description: "Skip Cache"
required: true
default: "false"
type: string
outputs:
cache-modifier:
description: "Cache Modifier"
value: ${{ jobs.prepare-cache.outputs.cache-modifier }}

jobs:
prepare-cache:
runs-on: ubuntu-latest
outputs:
cache-modifier: ${{ steps.set-cache-modifier.outputs.cache-modifier }}
steps:
- name: Set cache modifier
id: set-cache-modifier
run: |
if [[ "${{ inputs.skip-cache }}" == "true" ]] || [[ "$GITHUB_EVENT_NAME" == "schedule" ]]; then
echo "cache-modifier=$(date +%s)" >> $GITHUB_OUTPUT
else
echo "cache-modifier=" >> $GITHUB_OUTPUT
fi
71 changes: 56 additions & 15 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,35 @@ on:
workflow_call:
inputs:
environment:
description: The Github environment to load secrets from
type: string
required: true
netlify-context:
description: The Netlify context use when building
type: string
required: true
netlify-alias:
description: The Netlify alias to deploy to (empty deploys to production)
type: string
required: true
sha:
description: The commit SHA to deploy
type: string
required: true
runner-label:
description: The label of the runner to use
type: string
cache-modifier:
description: A modifier for the cache key used to bypass existing cache
type: string
required: false
default: ""

jobs:
netlify-deploy:
environment: ${{ inputs.environment }}
runs-on: ubuntu-latest
runs-on:
labels: ${{ inputs.runner-label || 'ubuntu-latest' }}
defaults:
run:
shell: bash
Expand All @@ -19,35 +42,33 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
ref: ${{ inputs.sha }}

- name: Read node modules from cache
id: cache-nodemodules
uses: actions/cache/restore@v3
uses: actions/cache/restore@v4
env:
cache-name: cache-install-folder
with:
path: |
site/gatsby-site/node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}-${{ inputs.cache-modifier }}

- name: Set up Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4

- name: Install dependencies
if: steps.cache-nodemodules.outputs.cache-hit != 'true'
run: npm ci

- name: Use new netlify.toml
run: |
rm -f netlify.toml
mv github-netlify.toml netlify.toml
- name: Use deploy specific netlify.toml
run: mv deploy-netlify.toml netlify.toml

- name: Install Netlify CLI
run: npm install netlify-cli -g

- name: Build using Netlify
run: netlify build --context deploy-preview --offline
run: netlify build --context ${{ inputs.netlify-context }} --offline
env:
NETLIFY_SITE_ID: ${{ vars.NETLIFY_SITE_ID }}
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
Expand All @@ -65,6 +86,7 @@ jobs:
MONGODB_CONNECTION_STRING: ${{ secrets.MONGODB_CONNECTION_STRING }}
MONGODB_REPLICA_SET: ${{ secrets.MONGODB_REPLICA_SET }}
MONGODB_TRANSLATIONS_CONNECTION_STRING: ${{ secrets.MONGODB_TRANSLATIONS_CONNECTION_STRING }}
TRANSLATE_SUBMISSION_DATE_START: ${{ vars.TRANSLATE_SUBMISSION_DATE_START }}
MONGODB_MIGRATIONS_CONNECTION_STRING: ${{ secrets.MONGODB_MIGRATIONS_CONNECTION_STRING }}
GATSBY_REALM_APP_GRAPHQL_URL: ${{ secrets.GATSBY_REALM_APP_GRAPHQL_URL }}
GATSBY_PRISMIC_REPO_NAME: ${{ vars.GATSBY_PRISMIC_REPO_NAME }}
Expand All @@ -78,13 +100,20 @@ jobs:
CLOUDFLARE_R2_ACCESS_KEY_ID: ${{ secrets.CLOUDFLARE_R2_ACCESS_KEY_ID }}
CLOUDFLARE_R2_SECRET_ACCESS_KEY: ${{ secrets.CLOUDFLARE_R2_SECRET_ACCESS_KEY }}
REALM_GRAPHQL_API_KEY: ${{ secrets.REALM_GRAPHQL_API_KEY }}
GATSBY_COMMIT_SHA: ${{ inputs.sha }}

- name: Upload to netlify
id: deploy-netlify
working-directory: site/gatsby-site
run: |
set -e
OUTPUT=$(bash -c "netlify deploy --json --alias=pr-${{ github.event.pull_request.number }}" | tr '\n' ' ')
# If no alias is specified, deploy to production
if [[ -z "${{ inputs.netlify-alias }}" ]]; then
OUTPUT=$(bash -c "netlify deploy --json --prod" | tr '\n' ' ')
# Otherwise, deploy to the specified alias
else
OUTPUT=$(bash -c "netlify deploy --json --alias=${{ inputs.netlify-alias }}" | tr '\n' ' ')
fi
set +e
NETLIFY_OUTPUT=$(echo "$OUTPUT")
echo "deploy_log=$NETLIFY_OUTPUT" >> $GITHUB_OUTPUT
Expand All @@ -93,16 +122,28 @@ jobs:
NETLIFY_SITE_ID: ${{ vars.NETLIFY_SITE_ID }}

- name: Comment on PR
uses: actions/github-script@v5
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const deployOutput = `${{ steps.deploy-netlify.outputs.deploy_log }}`;
const deployData = JSON.parse(deployOutput);
const comment = `🚀 Deployed to Netlify!\n\n✅ Build Log: \n${deployData.logs}\n\n🔗 Preview URL: ${deployData.deploy_url}`;
github.rest.issues.createComment({
issue_number: context.issue.number,
const { data: pullRequests } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
commit_sha: '${{ inputs.sha }}'
});
for (const pr of pullRequests) {
if (pr.state === 'open') {
github.rest.issues.createComment({
issue_number: pr.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
break; // Assuming you want to comment only on the first open PR
}
}
7 changes: 7 additions & 0 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- staging
types: [opened, synchronize, reopened]

jobs:
permissions-check:
runs-on: ubuntu-latest
Expand All @@ -31,14 +32,17 @@ jobs:
needs: permissions-check
secrets: inherit
with:
sha: ${{ github.event.pull_request.head.sha }}
environment: staging
netlify-context: deploy-preview

call-test:
if: ${{ !failure() }}
uses: ./.github/workflows/test.yml
needs: call-test-build
secrets: inherit
with:
sha: ${{ github.event.pull_request.head.sha }}
environment: staging

call-deploy:
Expand All @@ -49,4 +53,7 @@ jobs:
permissions:
pull-requests: write
with:
sha: ${{ github.event.pull_request.head.sha }}
environment: staging
netlify-context: deploy-preview
netlify-alias: pr-${{ github.event.pull_request.number }}
71 changes: 71 additions & 0 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Deploy Production Branch

on:
push:
branches:
- master
schedule:
- cron: "0 6,18 * * *"
workflow_dispatch:
inputs:
skip-cache:
description: "Skip Cache"
required: true
default: true
type: boolean
force-deploy:
description: "Deploy even if tests fail"
required: true
default: false
type: boolean
jobs:

cache-modifier:
uses: ./.github/workflows/cache-modifier.yml
with:
skip-cache: ${{ github.event.inputs.skip-cache }}

call-atlas:
uses: ./.github/workflows/realm.yml
secrets: inherit
needs: cache-modifier
with:
sha: ${{ github.sha }}
environment: production
runner-label: ${{ vars.PRODUCTION_RUNNER_LABEL }}

call-test-build:
uses: ./.github/workflows/test-build.yml
secrets: inherit
needs: [cache-modifier, call-atlas]
with:
sha: ${{ github.sha }}
environment: production
netlify-context: production
runner-label: ${{ vars.PRODUCTION_RUNNER_LABEL }}
cache-modifier: ${{ needs.cache-modifier.outputs.cache-modifier }}

call-test:
uses: ./.github/workflows/test.yml
needs: [cache-modifier, call-test-build]
secrets: inherit
with:
sha: ${{ github.sha }}
environment: production
runner-label: ${{ vars.PRODUCTION_RUNNER_LABEL }}
cache-modifier: ${{ needs.cache-modifier.outputs.cache-modifier }}

call-deploy:
if: inputs.force-deploy == true || success()
uses: ./.github/workflows/deploy.yml
needs: [cache-modifier, call-test]
secrets: inherit
permissions:
pull-requests: write
with:
environment: production
sha: ${{ github.sha }}
netlify-context: production
netlify-alias:
runner-label: ${{ vars.PRODUCTION_RUNNER_LABEL }}
cache-modifier: ${{ needs.cache-modifier.outputs.cache-modifier }}
2 changes: 1 addition & 1 deletion .github/workflows/realm-empty-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
npm install -g mongodb-realm-cli
- name: Login
run: |
realm-cli login --api-key="${{ secrets.REALM_API_PUBLIC_KEY }}" --private-api-key="${{ secrets.REALM_API_PRIVATE_KEY }}" --realm-url https://realm.mongodb.com --atlas-url https://cloud.mongodb.com
realm-cli login --api-key="${{ secrets.REALM_API_PUBLIC_KEY }}" --private-api-key="${{ secrets.REALM_API_PRIVATE_KEY }}" --realm-url https://services.cloud.mongodb.com --atlas-url https://cloud.mongodb.com
- name: Push
run: |
cd site/realm
Expand Down
23 changes: 0 additions & 23 deletions .github/workflows/realm-production.yml

This file was deleted.

24 changes: 0 additions & 24 deletions .github/workflows/realm-staging.yml

This file was deleted.

40 changes: 40 additions & 0 deletions .github/workflows/realm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Realm Deploy

on:
workflow_call:
inputs:
environment:
description: The Github environment to load secrets from
type: string
required: true
sha:
description: The commit SHA to deploy
type: string
required: true
runner-label:
description: The label of the runner to use
type: string

jobs:
push:
runs-on:
labels: ${{ inputs.runner-label || 'ubuntu-latest' }}
environment: ${{ inputs.environment }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.sha }}

- name: "Install the Realm (Atlas) CLI"
run: |
npm install -g mongodb-realm-cli
- name: Login
run: |
realm-cli login --api-key="${{ secrets.REALM_API_PUBLIC_KEY }}" --private-api-key="${{ secrets.REALM_API_PRIVATE_KEY }}" --realm-url https://services.cloud.mongodb.com --atlas-url https://cloud.mongodb.com
- name: Push
run: |
cd site/realm
realm-cli push --remote="${{ vars.GATSBY_REALM_APP_ID }}" -y
14 changes: 0 additions & 14 deletions .github/workflows/run_build.yml

This file was deleted.

Loading

0 comments on commit e86db3b

Please sign in to comment.