Skip to content

Merge pull request #6 from beyondessential/update-20240530 #7

Merge pull request #6 from beyondessential/update-20240530

Merge pull request #6 from beyondessential/update-20240530 #7

name: Fake DB Dump
on:
workflow_dispatch:
push:
env:
NODE_OPTIONS: "--max-old-space-size=6144"
NODE_ENV: test
NODE_MODULES_PATHS: |
node_modules
packages/*/node_modules
!packages/mobile/node_modules
jobs:
generate-fake:
if: >-
github.event_name == 'workflow_dispatch' || (
github.event_name == 'push' && (
github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/heads/release/') ||
startsWith(github.ref, 'refs/tags/') ||
contains(github.event.commits.*.message, '[generate-fake-db]')
)
)
strategy:
fail-fast: false
matrix:
postgres:
- "12"
- "14"
- "15"
- "16"
name: Make a db dump of fake data for pg${{ matrix.postgres }}
runs-on: ubuntu-latest
env:
ARTIFACT_NAME: fake-pg${{ matrix.postgres }}
steps:
- uses: actions/checkout@v4
id: autocheckout
if: >-
github.event_name == 'workflow_dispatch' || (
github.event_name == 'push' && (
github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/heads/release/') ||
startsWith(github.ref, 'refs/tags/')
)
)
- uses: actions/github-script@v7
if: steps.autocheckout.conclusion == 'skipped'
id: commit
with:
result-encoding: string
script: |
for (const { message, id } of context.payload.commits) {
console.log(id, message);
if (message.includes('[generate-fake-db]')) {
return id;
}
}
- uses: actions/checkout@v4
if: steps.commit.conclusion == 'success'
with:
ref: ${{ steps.commit.outputs.result }}
- uses: actions/setup-node@v4
with:
node-version: 20.x
cache: yarn
- uses: actions/cache/restore@v3
with:
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
path: ${{ env.NODE_MODULES_PATHS }}
- run: yarn
- run: yarn build-shared
- name: Install and start postgres ${{ matrix.postgres }}
run: |
source .github/scripts/install-postgres-ubuntu.sh ${{ matrix.postgres }}
.github/scripts/setup-postgres-for-one-package.sh fake
- run: yarn workspace scripts run generate-fake-db
- run: pg_dump fake --format custom --file $ARTIFACT_NAME.dump
- uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.ARTIFACT_NAME }}.dump
upload:
needs: generate-fake
runs-on: ubuntu-latest
permissions:
id-token: write # allow accessing OIDC token for AWS
contents: read
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-region: ap-southeast-2
role-to-assume: arn:aws:iam::143295493206:role/gha-tamanu-test-data-snapshots-s3
role-session-name: GHA@fake=generate
- uses: actions/download-artifact@v4
with:
path: fake
pattern: fake-*
merge-multiple: true
- name: Push to S3
run: aws s3 sync fake s3://bes-tamanu-test-data-snapshots/${{ github.sha }} --no-progress