forked from HumanSignal/label-studio
-
Notifications
You must be signed in to change notification settings - Fork 3
147 lines (126 loc) · 5.05 KB
/
follow-merge-upstream-repo-sync.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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 }}