Merge branch 'stage' into prod #232
This file contains 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 | |
on: | |
push: | |
branches: | |
- prod | |
- stage | |
paths: | |
- './github/workflows/deploy-assets.yml' | |
- './github/workflows/deploy-resources.yml' | |
- 'ops/deploy/deploy-resources.js' | |
- 'ops/deploy/deploy-sections.js' | |
- 'ops/deploy/deploy-documents.js' | |
- 'ops/deploy/deploy-categories.js' | |
- 'ops/deploy/deploy-authors.js' | |
- 'ops/deploy/deploy-languages.js' | |
- 'ops/sync/*.js' | |
- 'src/**/*.png' | |
- 'src/**/*.jpg' | |
- 'src/**/*.jpeg' | |
- 'src/**/*.mp3' | |
- 'src/**/*.mp4' | |
- 'src/**/*.md' | |
- 'src/**/*.yml' | |
- '!src/**/audio.yml' | |
- '!src/**/video.yml' | |
- '!src/**/pdf.yml' | |
jobs: | |
transfer-resource-assets: | |
if: (github.repository == 'Adventech/sabbath-school-resources') | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
name: Fetch the repository files | |
- name: Extract branch name | |
shell: bash | |
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" | |
id: extract_branch | |
- uses: actions/setup-node@v3 | |
name: Setup Node | |
with: | |
node-version: '16' | |
- name: Add token for private packages | |
run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.PACKAGES_SECRET }}" >> .npmrc | |
- run: npm install --global yarn | |
name: Install Yarn | |
- run: yarn install | |
name: Installing dependencies | |
- run: gpg --quiet --batch --yes --decrypt --passphrase="$CREDS_PASSPHRASE" --output deploy-creds.tar deploy-creds.tar.gpg | |
env: | |
CREDS_PASSPHRASE: ${{ secrets.CREDS_PASSPHRASE }} | |
working-directory: ops/deploy/creds | |
- run: tar xvf deploy-creds.tar | |
working-directory: ops/deploy/creds | |
- run: aws s3 cp assets s3://sabbath-school-resources-assets.adventech.io/assets --acl "public-read" --region us-east-1 --no-progress --recursive | |
name: Upload global assets | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
- run: find assets -mindepth 1 ! -name ".gitkeep" -exec rm -rf {} + | |
name: Delete global assets content | |
- run: aws s3 cp ./src s3://sabbath-school-resources-assets.adventech.io/ --acl "public-read" --region us-east-1 --no-progress --recursive --exclude "*" --include "**/assets/cover.png" --include "**/assets/cover-landscape.png" --include "**/assets/cover-square.png" --include "**/assets/splash.png" --include "**/assets/fonts/*.ttf" | |
name: Upload resource assets | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
- run: node ops/sync/transfer-resource-assets.js | |
name: Updating the source files with the remote urls and removing the files | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
DEPLOY_ENV: ${{ steps.extract_branch.outputs.branch }} | |
- name: Reset .npmrc | |
run: git restore .npmrc | |
- name: Commit & Push changes | |
uses: actions-js/push@master | |
with: | |
branch: ${{ steps.extract_branch.outputs.branch }} | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
download-and-transfer-document-assets: | |
needs: [transfer-resource-assets] | |
if: (github.repository == 'Adventech/sabbath-school-resources') | |
runs-on: ubuntu-latest | |
steps: | |
- name: Activate Globstar | |
run: shopt -s globstar | |
- name: Extract branch name | |
shell: bash | |
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" | |
id: extract_branch | |
- uses: actions/checkout@v4 | |
name: Fetch the repository files | |
with: | |
ref: ${{ steps.extract_branch.outputs.branch }} | |
- uses: actions/setup-node@v3 | |
name: Setup Node | |
with: | |
node-version: '16' | |
- name: Add token for private packages | |
run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.PACKAGES_SECRET }}" >> .npmrc | |
- run: npm install --global yarn | |
name: Install Yarn | |
- run: yarn install | |
name: Installing dependencies | |
- run: gpg --quiet --batch --yes --decrypt --passphrase="$CREDS_PASSPHRASE" --output deploy-creds.tar deploy-creds.tar.gpg | |
env: | |
CREDS_PASSPHRASE: ${{ secrets.CREDS_PASSPHRASE }} | |
working-directory: ops/deploy/creds | |
- run: tar xvf deploy-creds.tar | |
working-directory: ops/deploy/creds | |
- run: node ops/sync/set-aspect-ratios.js | |
name: Set aspect ratios of images | |
env: | |
DEPLOY_ENV: ${{ steps.extract_branch.outputs.branch }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- run: node ops/sync/transfer-document-assets.js | |
name: Generate transfer commands (seds) to replace locally referenced assets with the remote URLs | |
env: | |
DEPLOY_ENV: ${{ steps.extract_branch.outputs.branch }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- run: test -f transfer_commands.txt && source transfer_commands.txt | |
name: Run transfer commands if exists | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
- run: test -f transfer_commands.txt && rm transfer_commands.txt | |
name: Clean up | |
- run: mkdir download | |
name: Creating download directory | |
- run: grep -Poir '\!\[(.*?)\]\((http|https)://(?!sabbath-school)[a-zA-Z0-9./?=_%:-]*\)' --include="*.md" ./src > detected_links.txt || true | |
name: Finding all external links in the markdown files and saving to detected_links.txt | |
- run: node ops/sync/download-document-assets.js | |
name: Running script to generate transfer commands | |
env: | |
DEPLOY_ENV: ${{ steps.extract_branch.outputs.branch }} | |
- run: test -f download_commands.txt && bash download_commands.txt | |
name: Run download commands if exists | |
- run: aws s3 cp ./download s3://sabbath-school-resources-assets.adventech.io --acl "public-read" --region us-east-1 --no-progress --recursive | |
name: Upload all downloaded files | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
- run: test -f transfer_commands.txt && source transfer_commands.txt | |
name: Run transfer commands if exists | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
- run: test -f detected_links.txt && rm detected_links.txt | |
- run: test -f download_commands.txt && rm download_commands.txt | |
- run: test -f transfer_commands.txt && rm transfer_commands.txt | |
- run: rm -rf download | |
- name: Reset .npmrc | |
run: git restore .npmrc | |
- name: Commit & Push changes | |
uses: actions-js/push@master | |
with: | |
branch: ${{ steps.extract_branch.outputs.branch }} | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
call-deploy-resources: | |
uses: ./.github/workflows/deploy-resources.yml | |
needs: [transfer-resource-assets, download-and-transfer-document-assets] | |
with: | |
branch: ${{ github.ref_name }} | |
secrets: inherit |