Skip to content

Commit

Permalink
Push to wp-softcatala on release
Browse files Browse the repository at this point in the history
  • Loading branch information
ccoreilly committed Dec 29, 2024
1 parent 644c372 commit bc6c01a
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 22 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Build Application

on:
workflow_call:
inputs:
env_file:
required: false
type: boolean
default: false
secrets:
DUBBING_API_BASE_URL:
required: false
TRANSCRIPTION_API_BASE_URL:
required: false
MATXA_API_BASE_URL:
required: false

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "18"

- name: Install dependencies
run: npm ci

- name: Load .env.production
if: inputs.env_file
run: |
echo "DUBBING_API_BASE_URL=$(grep DUBBING_API_BASE_URL .env.production | cut -d '=' -f2)" >> $GITHUB_ENV
echo "TRANSCRIPTION_API_BASE_URL=$(grep TRANSCRIPTION_API_BASE_URL .env.production | cut -d '=' -f2)" >> $GITHUB_ENV
echo "MATXA_API_BASE_URL=$(grep MATXA_API_BASE_URL .env.production | cut -d '=' -f2)" >> $GITHUB_ENV
echo "APP_MODE=$(grep APP_MODE .env.production | cut -d '=' -f2)" >> $GITHUB_ENV
echo "APP_LANGUAGE=$(grep APP_LANGUAGE .env.production | cut -d '=' -f2)" >> $GITHUB_ENV
- name: Build
run: npm run build:prod
env:
DUBBING_API_BASE_URL: ${{ inputs.env_file && env.DUBBING_API_BASE_URL || secrets.DUBBING_API_BASE_URL }}
TRANSCRIPTION_API_BASE_URL: ${{ inputs.env_file && env.TRANSCRIPTION_API_BASE_URL || secrets.TRANSCRIPTION_API_BASE_URL }}
MATXA_API_BASE_URL: ${{ inputs.env_file && env.MATXA_API_BASE_URL || secrets.MATXA_API_BASE_URL }}
APP_MODE: ${{ inputs.env_file && env.APP_MODE || 'production' }}
APP_LANGUAGE: ${{ inputs.env_file && env.APP_LANGUAGE || 'ca' }}

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
34 changes: 12 additions & 22 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,22 @@ on:
- main

jobs:
build-and-deploy:
build:
uses: ./.github/workflows/build.yml
with:
env_file: true

deploy:
needs: build
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
node-version: "18"
- name: Install dependencies
run: npm ci
- name: Load .env.production
run: |
echo "DUBBING_API_BASE_URL=$(grep DUBBING_API_BASE_URL .env.production | cut -d '=' -f2)" >> $GITHUB_ENV
echo "TRANSCRIPTION_API_BASE_URL=$(grep TRANSCRIPTION_API_BASE_URL .env.production | cut -d '=' -f2)" >> $GITHUB_ENV
echo "MATXA_API_BASE_URL=$(grep MATXA_API_BASE_URL .env.production | cut -d '=' -f2)" >> $GITHUB_ENV
echo "APP_MODE=$(grep APP_MODE .env.production | cut -d '=' -f2)" >> $GITHUB_ENV
echo "APP_LANGUAGE=$(grep APP_LANGUAGE .env.production | cut -d '=' -f2)" >> $GITHUB_ENV
- name: Build
run: npm run build:prod
env:
DUBBING_API_BASE_URL: ${{ env.DUBBING_API_BASE_URL }}
TRANSCRIPTION_API_BASE_URL: ${{ env.TRANSCRIPTION_API_BASE_URL }}
MATXA_API_BASE_URL: ${{ env.MATXA_API_BASE_URL }}
APP_MODE: ${{ env.APP_MODE }}
APP_LANGUAGE: ${{ env.APP_LANGUAGE }}
name: dist
path: dist

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/sync-to-wp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Sync to WordPress Theme

on:
release:
types: [published]

jobs:
build:
uses: ./.github/workflows/build.yml
secrets:
DUBBING_API_BASE_URL: ${{ secrets.DUBBING_API_BASE_URL }}
TRANSCRIPTION_API_BASE_URL: ${{ secrets.TRANSCRIPTION_API_BASE_URL }}
MATXA_API_BASE_URL: ${{ secrets.MATXA_API_BASE_URL }}

sync:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist

- name: Find JS filename
id: find-js
run: |
JS_FILE=$(find dist/assets -name "index-*.js" -type f)
echo "js_file=$JS_FILE" >> $GITHUB_OUTPUT
- name: Checkout wp-softcatala repository
uses: actions/checkout@v4
with:
repository: Softcatala/wp-softcatala
token: ${{ secrets.WP_REPO_TOKEN }}

- name: Copy JS file
run: |
cp ${{ steps.find-js.outputs.js_file }} static/js/subdub-editor.js
- name: Commit and push changes
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add static/js/subdub-editor.js
git commit -m "Update subdub-editor.js to version ${{ github.event.release.tag_name }}"
git push origin HEAD:master

0 comments on commit bc6c01a

Please sign in to comment.