Skip to content

Commit

Permalink
Merge branch 'main' into fix-getcapabilities-type
Browse files Browse the repository at this point in the history
  • Loading branch information
Tjalling-dejong committed Jan 24, 2025
2 parents a40e8df + 67c7037 commit 8d58e07
Show file tree
Hide file tree
Showing 16 changed files with 1,970 additions and 13 deletions.
135 changes: 135 additions & 0 deletions .github/workflows/main-migrations.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
name: Deploy to production

on:
push:
branches:
- main

jobs:
apply-main-migrations:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Cache Node.js modules
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Check for changes in migrations folder
id: check_changes
run: |
git fetch origin main
if git diff --quiet HEAD^ 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-main

prepare:
needs: apply-main-migrations
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Cache Node.js modules
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Install dependencies
run: npm install --force

- name: Set matrix data
id: set-matrix
run: |
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"
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: Cache Node.js modules
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Install dependencies
run: npm install --force

- name: Build application
run: NODE_OPTIONS="--openssl-legacy-provider" npm run build
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 }}
DATO_INSTANCE_CURRENT: ${{ matrix.name }}
DATO_ENVIRONMENT: main
VUE_APP_MAPBOX_TOKEN: ${{ secrets.VUE_APP_MAPBOX_TOKEN }}
VUE_APP_API_ENDPOINT: ${{ secrets.VUE_APP_API_ENDPOINT }}
VUE_APP_AQUADESK_KEY: ${{ secrets.VUE_APP_AQUADESK_KEY }}
VUE_APP_PIWIK_CONTAINER_ID: ${{ secrets.VUE_APP_PIWIK_CONTAINER_ID }}
VUE_APP_WMR_KEY: ${{ secrets.VUE_APP_WMR_KEY }}
DEEPL_KEY: ${{ secrets.DEEPL_KEY }}

- name: Deploy to Netlify
uses: nwtgck/[email protected]
with:
publish-dir: "./dist"
production-branch: main
github-token: ${{ secrets.GITHUB_TOKEN }}
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ matrix.netlifySiteId }}
115 changes: 115 additions & 0 deletions .github/workflows/staging-migrations.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: Deploy to staging

on:
pull_request:
types: [opened, synchronize]

jobs:
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:
needs: apply-staging-migrations
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:
node-version: "20"

- name: Install dependencies
run: npm install --force

- name: Set matrix data
id: set-matrix
run: |
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"
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
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Install dependencies
run: npm install --force

- name: Build application
run: NODE_OPTIONS="--openssl-legacy-provider" npm run build
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 }}
DATO_INSTANCE_CURRENT: ${{ matrix.name }}
DATO_ENVIRONMENT: staging
VUE_APP_MAPBOX_TOKEN: ${{ secrets.VUE_APP_MAPBOX_TOKEN }}
VUE_APP_API_ENDPOINT: ${{ secrets.VUE_APP_API_ENDPOINT }}
VUE_APP_AQUADESK_KEY: ${{ secrets.VUE_APP_AQUADESK_KEY }}
VUE_APP_PIWIK_CONTAINER_ID: ${{ secrets.VUE_APP_PIWIK_CONTAINER_ID }}
VUE_APP_WMR_KEY: ${{ secrets.VUE_APP_WMR_KEY }}
DEEPL_KEY: ${{ secrets.DEEPL_KEY }}

- name: Deploy to Netlify
uses: nwtgck/[email protected]
with:
publish-dir: "./dist"
production-branch: main
github-token: ${{ secrets.GITHUB_TOKEN }}
enable-commit-comment: false
enable-pull-request-comment: true
overwrites-pull-request-comment: true
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ matrix.netlifySiteId }}
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,25 @@ For each instance:
Usage:

```bash
bash
npm run migrations:apply-main
```

This update adds a new section to the `README.md` file, documenting the `apply-main` script and its usage.
## GitHub Actions Workflows

### Deploy to Production

The `main-migrations.yaml` workflow is triggered on a push to the `main` branch. It performs the following steps:

1. Checks out the repository.
1. Checks for changes in the `migrations` folder.
1. If changes are detected, sets up Node.js, installs dependencies, and runs the `migrations:apply-main` script.
1. Deploys the application to Netlify using the specified instances.

### Deploy to Staging

The `staging-migrations.yaml` workflow is triggered on pull request events (opened or synchronized). It performs the following steps:

1. Checks out the repository.
1. Checks for changes in the `migrations` folder.
1. If changes are detected, sets up Node.js, installs dependencies, and runs the `migrations:apply-staging` script.
1. Deploys the application to Netlify using the specified instances.
2 changes: 1 addition & 1 deletion config/dato/datocms.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion config/dato/instances.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const instances: Array<{
name: string;
key: string;
datoApiKey: string;
netlifySiteId: string;
}>;
9 changes: 6 additions & 3 deletions config/dato/instances.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
];
17 changes: 17 additions & 0 deletions migrations/1727855666_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Client } from "@datocms/cli/lib/cma-client-node";

export default async function (client: Client): Promise<void> {
const articleModel = await client.itemTypes.create({
name: "Article",
api_key: "article",
});

await client.fields.create(articleModel, {
label: "Title",
api_key: "title",
field_type: "string",
validators: {
required: {},
},
});
}
Loading

0 comments on commit 8d58e07

Please sign in to comment.