diff --git a/.github/workflows/main-migrations.yaml b/.github/workflows/main-migrations.yaml index de78c042..31e7d4fb 100644 --- a/.github/workflows/main-migrations.yaml +++ b/.github/workflows/main-migrations.yaml @@ -1,4 +1,4 @@ -name: Main migrations +name: Deploy production on: pull_request: diff --git a/.github/workflows/staging-migrations.yaml b/.github/workflows/staging-migrations.yaml index 6de532c4..2244edf7 100644 --- a/.github/workflows/staging-migrations.yaml +++ b/.github/workflows/staging-migrations.yaml @@ -1,45 +1,97 @@ -name: Staging migrations +name: Deploy staging on: pull_request: types: [opened, synchronize] jobs: - apply-staging-migrations: + # apply-staging-migrations: + # runs-on: ubuntu-latest + # steps: + # - name: Checkout repository + # uses: actions/checkout@v4 + # with: + # fetch-depth: 0 + + # - name: Check for changes in migrations folder + # id: check_changes + # run: | + # git fetch origin main + # git fetch origin ${{ github.head_ref || github.ref_name }} + # git checkout ${{ github.head_ref || github.ref_name }} + + # if git diff --quiet origin/main HEAD -- migrations; then + # echo "CHANGES=false" >> $GITHUB_ENV + # else + # echo "CHANGES=true" >> $GITHUB_ENV + # fi + + # - name: Set up Node.js + # if: ${{ env.CHANGES == 'true' }} + # uses: actions/setup-node@v4 + # with: + # node-version: "20" + + # - name: Install dependencies + # if: ${{ env.CHANGES == 'true' }} + # run: npm install --force + + # - name: Run TypeScript script + # if: ${{ env.CHANGES == 'true' }} + # env: + # DATO_API_KEY_OPENEARTH_RWS_VIEWER: ${{ secrets.DATO_API_KEY_OPENEARTH_RWS_VIEWER }} + # DATO_API_KEY_OPENEARTH_DATA_VIEWER: ${{ secrets.DATO_API_KEY_OPENEARTH_DATA_VIEWER }} + # DATO_API_KEY_NL2120: ${{ secrets.DATO_API_KEY_NL2120 }} + # run: npm run migrations:apply-staging + + prepare: runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} steps: - name: Checkout repository uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 with: - fetch-depth: 0 + node-version: "20" - - name: Check for changes in migrations folder - id: check_changes + - name: Install dependencies + run: npm install --force + + - name: Set matrix data + id: set-matrix run: | - git fetch origin main - git fetch origin ${{ github.head_ref || github.ref_name }} - git checkout ${{ github.head_ref || github.ref_name }} + instances=$(node -e 'console.log(JSON.stringify(require("./config/dato/instances.js").instances))') + echo "matrix=$(echo $instances | jq -c '.')" >> $GITHUB_OUTPUT + echo "matrix is set to: $instances" - if git diff --quiet origin/main HEAD -- migrations; then - echo "CHANGES=false" >> $GITHUB_ENV - else - echo "CHANGES=true" >> $GITHUB_ENV - fi + deploy-application: + needs: prepare + runs-on: ubuntu-latest + strategy: + matrix: + include: ${{ fromJson(needs.prepare.outputs.matrix) }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 - name: Set up Node.js - if: ${{ env.CHANGES == 'true' }} uses: actions/setup-node@v4 with: node-version: "20" - name: Install dependencies - if: ${{ env.CHANGES == 'true' }} run: npm install --force - - name: Run TypeScript script - if: ${{ env.CHANGES == 'true' }} + - name: Deploy to Netlify + uses: nwtgck/actions-netlify@v3.0 + with: + publish-dir: "./dist" + production-branch: main + github-token: ${{ secrets.GITHUB_TOKEN }} + deploy-message: "Deploy from GitHub Actions" env: - DATO_API_KEY_OPENEARTH_RWS_VIEWER: ${{ secrets.DATO_API_KEY_OPENEARTH_RWS_VIEWER }} - DATO_API_KEY_OPENEARTH_DATA_VIEWER: ${{ secrets.DATO_API_KEY_OPENEARTH_DATA_VIEWER }} - DATO_API_KEY_NL2120: ${{ secrets.DATO_API_KEY_NL2120 }} - run: npm run migrations:apply-staging + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} + NETLIFY_SITE_ID: ${{ matrix.netlifySiteId }} diff --git a/config/dato/datocms.mjs b/config/dato/datocms.mjs index 4a400d70..d370b3a0 100644 --- a/config/dato/datocms.mjs +++ b/config/dato/datocms.mjs @@ -23,7 +23,7 @@ if (!currentInstance) { throw new Error("No current instance found"); } -const token = currentInstance.key; +const token = currentinstance.datoApiKey; const endpoint = process.env.NODE_ENV === 'production' diff --git a/config/dato/instances.js b/config/dato/instances.js index 79d5a7d8..38affcad 100644 --- a/config/dato/instances.js +++ b/config/dato/instances.js @@ -5,14 +5,17 @@ dotenv.config(); module.exports.instances = [ { name: "nl2120", - key: process.env.DATO_API_KEY_NL2120, + datoApiKey: process.env.DATO_API_KEY_NL2120, + netlifySiteId: "1f6372f6-c532-4e0e-bba7-dee08678d518", }, { name: "openearth-data-viewer", - key: process.env.DATO_API_KEY_OPENEARTH_DATA_VIEWER, + datoApiKey: process.env.DATO_API_KEY_OPENEARTH_DATA_VIEWER, + netlifySiteId: "1785f3f6-b4cf-42de-bea6-b57d48a5c664", }, { name: "openearth-rws-viewer", - key: process.env.DATO_API_KEY_OPENEARTH_RWS_VIEWER, + datoApiKey: process.env.DATO_API_KEY_OPENEARTH_RWS_VIEWER, + netlifySiteId: "119b8ff3-5b22-4995-b43b-b31f21ba77c3", }, ]; diff --git a/scripts/dato/apply-main.ts b/scripts/dato/apply-main.ts index d514f15b..3bd5749e 100644 --- a/scripts/dato/apply-main.ts +++ b/scripts/dato/apply-main.ts @@ -7,7 +7,7 @@ async function main() { for (const instance of instances) { console.log(`Managing environments for ${instance.name}`); - const client = new DatoClient(instance.key); + const client = new DatoClient(instance.datoApiKey); await client.runCommand(["maintenance:on"]); diff --git a/scripts/dato/apply-staging.ts b/scripts/dato/apply-staging.ts index 1523cbbf..4ddebe3b 100644 --- a/scripts/dato/apply-staging.ts +++ b/scripts/dato/apply-staging.ts @@ -7,7 +7,7 @@ async function main() { for (const instance of instances) { console.log(`Setting up staging environment for ${instance.name}`); - const client = new DatoClient(instance.key); + const client = new DatoClient(instance.datoApiKey); const existingEnvironments = await client.listEnvironments(); diff --git a/scripts/dato/create.ts b/scripts/dato/create.ts index 94e57308..a663b062 100644 --- a/scripts/dato/create.ts +++ b/scripts/dato/create.ts @@ -12,7 +12,7 @@ if (!currentInstance) { throw new Error("No current instance found"); } -const apiKey = currentInstance.key; +const apiKey = currentinstance.datoApiKey; const client = new DatoClient(apiKey); const promptGet = promisify(prompt.get);