diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..1061c87 --- /dev/null +++ b/.github/workflows/build.yml @@ -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/ diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 563bdb0..ef80833 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -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: diff --git a/.github/workflows/sync-to-wp.yml b/.github/workflows/sync-to-wp.yml new file mode 100644 index 0000000..765afce --- /dev/null +++ b/.github/workflows/sync-to-wp.yml @@ -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