feat: update mednum schema (#114) #122
This file contains hidden or 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: Deploy API | |
on: | |
push: | |
branches: | |
- 'main' | |
permissions: | |
contents: write | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
id: build-checkout-repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
persist-credentials: false | |
- name: Prepare release | |
id: build-prepare-realise | |
uses: mgoltzsche/conventional-release@v0 | |
- name: Install pnpm | |
id: build-install-pnpm | |
uses: pnpm/action-setup@v2 | |
with: | |
version: 8.6.7 | |
- name: Set up Node.js | |
id: build-set-up-nodejs | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18.x' | |
cache: 'pnpm' | |
- name: Install dependencies | |
id: build-install-dependencies | |
run: pnpm install | |
- name: 'Create env file' | |
run: | | |
touch .env | |
echo BASE_URL="${{ secrets.BASE_URL }}" >> .env | |
- name: Build | |
id: build-build | |
run: pnpm build | |
- name: Build OpenApi | |
id: doc-build-openapi | |
run: pnpm build.openapi | |
- name: Prepare and zip build files | |
id: build-prepare-and-zip-build-files | |
run: | | |
for file in dist/*.mjs; do | |
filename=$(basename -- "$file") | |
filename_next="${filename%.*}" | |
mv "$file" "dist/index.mjs" | |
(cd dist && zip -r "$filename_next.zip" "index.mjs" "chunks") | |
rm "dist/index.mjs" | |
done | |
mv openapi.json dist | |
rm -rf dist/chunks | |
- name: Upload build artifact | |
id: build-upload-build-artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: build | |
path: dist | |
doc: | |
name: Generate documentation | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Checkout repository | |
id: doc-checkout-repository | |
uses: actions/checkout@v3 | |
- name: Install pnpm | |
id: doc-install-pnpm | |
uses: pnpm/action-setup@v2 | |
with: | |
version: 8.6.7 | |
- name: Set up Node.js | |
id: doc-set-up-nodejs | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18.x' | |
cache: 'pnpm' | |
- name: Install dependencies | |
id: doc-install-dependencies | |
run: pnpm install | |
- name: Fetch latest release version | |
id: doc-fetch-latest-release-version | |
uses: fangqiuming/latest-release-version@v1.2 | |
- name: Update openapirc.json version | |
id: doc-update-openapirc-version | |
run: | | |
VERSION="${{ steps.doc-fetch-latest-release-version.outputs.tag_name }}" | |
VERSION="${VERSION#v}" | |
jq --arg version "$VERSION" '.info.version = $version' .openapirc.json > .openapirc.updated.json | |
mv .openapirc.updated.json .openapirc.json | |
- name: Build OpenApi | |
id: doc-build-openapi | |
run: pnpm build.openapi | |
- name: Build Documentation | |
id: doc-build-documentation | |
run: pnpm build.openapi-doc | |
- name: Move doc to major version folder | |
id: doc-move-doc-to-major-version-folder | |
run: | | |
MAJOR_VERSION=$(echo ${{ steps.doc-fetch-latest-release-version.outputs.tag_name }} | cut -d '.' -f 1) | |
mkdir -p dist/$MAJOR_VERSION | |
mv dist/index.html dist/$MAJOR_VERSION | |
- name: Upload build artifact | |
id: doc-upload-build-artifact | |
uses: actions/upload-pages-artifact@v2 | |
with: | |
name: doc | |
path: dist | |
publish-documentation: | |
name: Publish documentation | |
needs: doc | |
permissions: | |
pages: write | |
id-token: write | |
environment: | |
name: github-pages | |
runs-on: ubuntu-latest | |
steps: | |
- name: Deploy to GitHub Pages | |
id: publish-documentation-deploy-to-github-pages | |
uses: actions/deploy-pages@v2 | |
with: | |
artifact_name: doc | |
publish: | |
name: Publish | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Download build | |
id: publish-download-build | |
uses: actions/download-artifact@v3 | |
with: | |
name: build | |
path: build | |
- name: Fetch latest release version | |
id: publish-fetch-latest-release-version | |
uses: fangqiuming/latest-release-version@v1.2 | |
- name: Set Major Version | |
id: publish-set-major-version | |
run: echo "MAJOR_VERSION=$(echo ${{ steps.publish-fetch-latest-release-version.outputs.tag_name }} | cut -d '.' -f 1)" >> $GITHUB_ENV | |
- name: Publish on S3 | |
id: publish-publish-on-s3 | |
uses: jakejarvis/s3-sync-action@master | |
with: | |
args: --delete | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }} | |
SOURCE_DIR: 'build' | |
DEST_DIR: $MAJOR_VERSION | |
deploy: | |
name: Update API Gateway | |
needs: publish | |
uses: codingones/github-actions-workflows/.github/workflows/apply.terraform.yml@main | |
with: | |
infrastructure-repository: 'anct-cartographie-nationale/api-infrastructure' | |
workspace-name: 'api-production' | |
secrets: | |
TF_API_TOKEN: ${{ secrets.TF_API_TOKEN }} | |
reset-cache: | |
name: Reset Cache | |
runs-on: ubuntu-latest | |
needs: deploy | |
steps: | |
- name: Invalidate CloudFront | |
id: reset-cache-invalidate-cloudfront | |
uses: muratiger/invalidate-cloudfront-and-wait-for-completion-action@master | |
env: | |
PATHS: '/*' | |
DISTRIBUTION_ID: ${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID }} | |
AWS_REGION: 'us-east-1' | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
- name: Refresh lieux inclusion numerique | |
id: reset-cache-refresh-lieux-inclusion-numerique | |
run: curl -o output.json -H "Accept-Encoding:gzip, br" https://cartographie.societenumerique.gouv.fr/api/v0/lieux-inclusion-numerique |