upstream_repo_update #87
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: 'Sync from Label Studio frontend' | |
on: | |
# Triggered by either the scheduled weekly sync, or a PR merged to the main branch of Khan/label-studio-frontend. | |
repository_dispatch: | |
types: | |
- upstream_repo_update | |
# Adding for testing. | |
workflow_dispatch: | |
# Ensure only one job is running at a time to sync from frontend. For example, multiple could be triggered if | |
# PRs are merged to the frontend repo in quick succession. | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.client_payload.branch_name }} | |
env: | |
NODE: 18 | |
CACHE_NAME_PREFIX: v1 | |
STATIC_DIST: 'label_studio/frontend/dist' | |
DOCS_TARGET_DIR: "docs/source/tags/" | |
BACKEND_BASE_BRANCH: 'develop' | |
FRONTEND_BASE_BRANCH: 'master' | |
jobs: | |
open: | |
name: Sync PR | |
if: | | |
github.event.client_payload.event_action == 'merged' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: hmarr/[email protected] | |
- name: Configure git | |
shell: bash | |
run: | | |
set -xeuo pipefail | |
git config --global user.name 'khan-actions-bot' | |
git config --global user.email '[email protected]' | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.KHAN_ACTIONS_BOT_TOKEN }} | |
ref: ${{ env.BACKEND_BASE_BRANCH }} | |
fetch-depth: 0 | |
- name: Checkout module | |
uses: actions/checkout@v4 | |
with: | |
repository: Khan/label-studio-frontend | |
path: tmp | |
token: ${{ secrets.KHAN_ACTIONS_BOT_TOKEN }} | |
fetch-depth: 1 | |
ref: ${{ github.event.client_payload.commit_sha }} | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: "${{ env.NODE }}" | |
- name: Upgrade Yarn | |
run: npm install -g [email protected] | |
- name: Get yarn cache directory path | |
id: yarn-cache-dir-path | |
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT | |
- name: Configure yarn cache | |
uses: actions/cache@v3 | |
with: | |
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | |
key: ${{ env.CACHE_NAME_PREFIX }}-${{ runner.os }}-node-${{ env.NODE }}-${{ hashFiles('**/package.json') }}-${{ hashFiles('**/yarn.lock') }} | |
- name: Print Yarn cache size | |
run: du -d 0 -h ${{ steps.yarn-cache-dir-path.outputs.dir }} | |
- name: Install dependencies | |
run: | | |
rm package-lock.json || true | |
yarn install | |
working-directory: tmp | |
- name: Build module | |
working-directory: tmp | |
env: | |
CI: false # on true webpack breaks on warnings, and we have them a lot | |
NODE_ENV: 'production' | |
run: | | |
yarn run build:module | |
branch="${{ env.FRONTEND_BASE_BRANCH }}" | |
cat << EOF > "build/static/version.json" | |
{ | |
"message": "${{ github.event.client_payload.title }}", | |
"commit": "${{ github.event.client_payload.commit_sha }}", | |
"branch": "${branch}", | |
"date": "$(git log -1 --date=format:"%Y/%m/%d %T" --format="%ad" | cat)" | |
} | |
EOF | |
- name: "LSF Docs: Cache node modules" | |
uses: actions/cache@v3 | |
with: | |
path: ~/.npm | |
key: npm-${{ env.CACHE_NAME_PREFIX }}-${{ runner.os }}-node-${{ env.NODE }}-jsdoc-to-markdown | |
- name: "LSF Docs: Install NPM deps" | |
continue-on-error: true | |
run: npm install -g jsdoc-to-markdown node-fetch | |
- name: "LSF Docs: Build" | |
id: lsf-docs-build | |
continue-on-error: true | |
working-directory: tmp/scripts | |
run: node create-docs.js | |
- name: Commit static | |
shell: bash | |
run: | | |
set -xeuo pipefail | |
module_dist="${{ env.STATIC_DIST }}/lsf" | |
rm -rf "${module_dist}" | |
mkdir -p "${module_dist}" | |
cp -r tmp/build/static/* "${module_dist}" | |
git add "${{ env.STATIC_DIST }}" | |
git status -s | |
git commit --allow-empty -m '[submodules] Build static Khan/label-studio-frontend from commit ${{ github.event.client_payload.commit_sha }} at ${{ github.event.client_payload.html_url }}' -m 'Workflow run: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' | |
git push origin HEAD | |
- name: "LSF Docs: Commit" | |
if: steps.lsf-docs-build.conclusion == 'success' | |
continue-on-error: true | |
run: | | |
set -xeuo pipefail | |
docs_target_dir='${{ env.DOCS_TARGET_DIR }}' | |
find "${docs_target_dir}" ! -name 'index.md' -type f -exec rm -rf {} + | |
mkdir -p "${docs_target_dir}" | |
cp -Rf tmp/docs/* "${docs_target_dir}" | |
git status | |
git add "${docs_target_dir}" | |
git commit -m 'docs: LSF Update from commit ${{ github.event.client_payload.commit_sha }} at ${{ github.event.client_payload.html_url }}' -m 'Workflow run: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' | |
git push origin HEAD | |
- name: Notify Slack on failure | |
if: failure() | |
uses: ./.github/actions/notify_slack | |
with: | |
webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }} |