From a1d3a84614e93930fd973e13e8c0d246fbffcc34 Mon Sep 17 00:00:00 2001 From: Tim Eves Date: Mon, 16 Sep 2024 11:41:29 +0700 Subject: [PATCH] Upgrade SLDR build and deploy workflows (#33) * Emit artifact.id with repository dispatch event Record and include the built artifact id with the repository_dispatch event sent to langtags. * Update to node20 compatible actions * Add a cache to skip flattening and deployment of the sldr if it's not changed. * Restrict deployment to pushes or merges into master and release. For feature and fix branches we want to build, but not deploy until the are merged into their respective master and release branches. * Trigger staging builds, but not deploy, for any branch starting with `feat/` or `fix/` --- .github/workflows/build.yml | 24 ++++++++++++++++++++++-- .github/workflows/deploy.yml | 29 +++++++++++++++++------------ .github/workflows/production.yml | 14 ++++++++++---- .github/workflows/staging.yml | 16 ++++++++++------ .gitignore | 32 +++++++++++++++----------------- 5 files changed, 74 insertions(+), 41 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a99eb28ca..7020dc3d7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,25 +1,45 @@ name: Build on: workflow_call: + outputs: + artifact-id: + description: "The artifact id uploaded by this build" + value: ${{ jobs.build.outputs.artifact-id }} jobs: build: runs-on: ubuntu-latest + outputs: + artifact-id: ${{ steps.upload.outputs.artifact-id }} steps: - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: python-version: '3.10' - run: pip install 'git+https://github.com/silnrsi/sldrtools' - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + + - name: Use cached sldr + id: cache-sldr + uses: actions/cache@v4 + with: + path: | + flat + unflat + key: sldr-flattened-${{ hashFiles('sldr/**') }} - name: Generate unflattened sldr + if: steps.cache-sldr.outputs.cache-hit != 'true' run: ldmlflatten -o unflat -i sldr -a -c -g - name: Generate flattened sldr + if: steps.cache-sldr.outputs.cache-hit != 'true' run: ldmlflatten -o flat -i sldr -a -A -g - uses: actions/upload-artifact@v4 + id: upload + if: steps.cache-sldr.outputs.cache-hit != 'true' with: name: sldr path: | flat/ unflat/ + compression-level: 9 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b7e484db4..cd5d6f2c2 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,46 +2,51 @@ name: Deploy to server on: workflow_call: inputs: - stage_to: + stage-to: + required: true + type: string + artifact-id: required: true type: string secrets: - uploader_key: + uploader-key: required: true - server_address: + server-address: required: true - repository_dispatch_pat: + repository-dispatch-pat: required: true jobs: deploy: runs-on: ubuntu-latest + if: inputs.artifact-id env: RSYNC_OPTS: -aP --no-p --no-g --no-t --compress --del -e "ssh -o StrictHostKeyChecking=no" steps: # Install our private key for uploading deliverable - - uses: webfactory/ssh-agent@v0.7.0 + - uses: webfactory/ssh-agent@v0.9.0 with: - ssh-private-key: ${{secrets.uploader_key}} + ssh-private-key: ${{secrets.uploader-key}} # Download the artefact - uses: actions/download-artifact@v4 with: name: sldr # Upload results - - name: Upload flattened SLDR to /ldml-api/data/${{ inputs.stage }} - run: rsync ${{env.RSYNC_OPTS}} --chmod=Dug=rwx flat unflat ${{secrets.server_address}}/sites/s/ldml-api/data/${{ inputs.stage_to }}/ + - name: Upload flattened SLDR to /ldml-api/data/${{ inputs.stage-to }} + run: rsync ${{env.RSYNC_OPTS}} --chmod=Dug=rwx flat unflat ${{secrets.server-address}}/sites/s/ldml-api/data/${{ inputs.stage-to }}/ dispatch: runs-on: ubuntu-latest needs: deploy steps: - name: Trigger langtags rebuild - uses: peter-evans/repository-dispatch@v2 + uses: peter-evans/repository-dispatch@v3 with: - token: ${{ secrets.repository_dispatch_pat }} + token: ${{ secrets.repository-dispatch-pat }} repository: silnrsi/langtags - event-type: sldr${{ endsWith(github.ref, '/release') && '-release' || ''}}-deployed + event-type: sldr-deployed client-payload: >- { - "release": "${{ endsWith(github.ref, '/release') }}" + "release": "${{ github.ref_name == 'release' }}", + "artifact-id": ${{ inputs.artifact-id }} } diff --git a/.github/workflows/production.yml b/.github/workflows/production.yml index 4a2adfe8a..e96fb80f4 100644 --- a/.github/workflows/production.yml +++ b/.github/workflows/production.yml @@ -2,10 +2,14 @@ name: Flatten SLDR and publish release branch to production on: push: paths: + - .github/workflows/** - sldr/** branches: [ release ] pull_request: + types: + - closed paths: + - .github/workflows/** - sldr/** branches: [ release ] @@ -16,10 +20,12 @@ jobs: # Deploy built artefacts to the secrets.UPLOAD_TARGET deploy: needs: build + if: github.event_name == 'push' || github.event.pull_request.merged == true uses: ./.github/workflows/deploy.yml with: - stage_to: sldr + stage-to: sldr + artifact-id: ${{ needs.build.outputs.artifact-id }} secrets: - uploader_key: ${{ secrets.UPLOADER_SSH_KEY }} - server_address: ${{ secrets.UPLOAD_TARGET }} - repository_dispatch_pat: ${{ secrets.REPO_DISPATCH_TOKEN }} \ No newline at end of file + uploader-key: ${{ secrets.UPLOADER_SSH_KEY }} + server-address: ${{ secrets.UPLOAD_TARGET }} + repository-dispatch-pat: ${{ secrets.REPO_DISPATCH_TOKEN }} diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml index 01bdaecec..3abc2e819 100644 --- a/.github/workflows/staging.yml +++ b/.github/workflows/staging.yml @@ -1,11 +1,13 @@ -name: Flatten SLDR and publish to staging +name: Flatten SLDR and publish master to staging on: push: paths: - .github/workflows/** - sldr/** - branches: [ master ] + branches: [ master, feat/*, fix/* ] pull_request: + types: + - closed paths: - .github/workflows/** - sldr/** @@ -18,10 +20,12 @@ jobs: # Deploy built artefacts to the secrets.UPLOAD_TARGET deploy: needs: build + if: github.event_name == 'push' || github.event.pull_request.merged == true uses: ./.github/workflows/deploy.yml with: - stage_to: sldr-staging + stage-to: sldr-staging + artifact-id: ${{ needs.build.outputs.artifact-id }} secrets: - uploader_key: ${{ secrets.UPLOADER_SSH_KEY }} - server_address: ${{ secrets.UPLOAD_TARGET }} - repository_dispatch_pat: ${{ secrets.REPO_DISPATCH_TOKEN }} + uploader-key: ${{ secrets.UPLOADER_SSH_KEY }} + server-address: ${{ secrets.UPLOAD_TARGET }} + repository-dispatch-pat: ${{ secrets.REPO_DISPATCH_TOKEN }} diff --git a/.gitignore b/.gitignore index 59c76a8d0..853e6d8aa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,20 +1,18 @@ -.*.sw? +# runtime litter *.pyc -*~ -**/__pycache__/ -node_modules/ -vendor_bower/ -dev/ -flat/ -unflat/ -cldrdata/ -cldrflat/ -temp/ -results/ -keyboards/ -doc/*.rnc -sldr/*/*.orig -# Editors -*.bak +# build intermediates +*.egg-info/** +dist/ +build/ +/flat/** +/unflat/** +# dev environment +/.venv/ +/.vscode/ +*.code-workspace +*.env +*.secrets +*~ +*.bak \ No newline at end of file