-
Notifications
You must be signed in to change notification settings - Fork 2.5k
147 lines (130 loc) · 5.72 KB
/
frontend-command.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: "/frontend command"
on:
repository_dispatch:
types: [ frontend-command ]
env:
NODE: '18'
CACHE_NAME_PREFIX: v0
jobs:
build:
if: ${{ github.event.client_payload.slash_command.args.unnamed.arg1 == 'build' }}
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: hmarr/[email protected]
- name: Add Workflow link to command comment
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GIT_PAT }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: |
> [Workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
- name: Checkout on chat command
uses: actions/checkout@v4
with:
token: ${{ secrets.GIT_PAT }}
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
ref: ${{ github.event.client_payload.pull_request.head.ref }}
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: "${{ env.NODE }}"
- name: Get npm cache directory
id: npm-cache-dir
run: echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
name: Configure npm cache
id: npm-cache
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ env.CACHE_NAME_PREFIX }}-${{ runner.os }}-node-${{ env.NODE }}
- name: Get build
id: get_build
env:
GITHUB_TOKEN: ${{ secrets.GIT_PAT }}
REPO: ${{ github.event.client_payload.slash_command.args.unnamed.arg2 || 'all' }}
SHA: ${{ github.event.client_payload.slash_command.args.unnamed.arg3 || 'master' }}
run: |
set -xeuo pipefail
if [ "${REPO}" = "all" ]; then
node label_studio/frontend/get-build.js lsf | tee -a /tmp/output
grep 'Build link:' /tmp/output | cut -d":" -f2- >> /tmp/info_commit_msg
node label_studio/frontend/get-build.js dm | tee -a /tmp/output
grep 'Build link:' /tmp/output | cut -d":" -f2- >> /tmp/info_commit_msg
else
node label_studio/frontend/get-build.js "${REPO}" "${SHA}" | tee -a /tmp/output
grep 'Build link:' /tmp/output | cut -d":" -f2- >> /tmp/info_commit_msg
fi
{
echo "COMMIT_MSG_FILE<<EOF"
cat /tmp/info_commit_msg
echo "EOF"
} >> "${GITHUB_ENV}"
- name: Commit and push
id: commit_and_push
shell: bash
env:
REPO: ${{ github.event.client_payload.slash_command.args.unnamed.arg2 || 'all' }}
run: |
set -xeuo pipefail
git config --global user.name '${{ github.event.client_payload.github.actor }}'
git config --global user.email '${{ github.event.client_payload.github.actor }}@users.noreply.github.com'
git add -A
git status -s
if git diff-index --quiet HEAD; then
echo "changes=no" >> $GITHUB_OUTPUT
exit 0
else
git commit -m "[frontend] Get build ${REPO}" -m 'Workflow run: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'
fi
git push origin HEAD
- name: Add reaction to command comment on nothing to do
if: steps.commit_and_push.outputs.changes == 'no'
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GIT_PAT }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: |
> Already up-to-date. Nothing to commit.
reactions: "confused"
- name: Add reaction to command comment on success
if: steps.commit_and_push.outputs.changes != 'no'
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GIT_PAT }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: |
> Successfully pushed new changes
> ${{ env.COMMIT_MSG_FILE }}
reactions: "+1"
- name: Add reaction to command comment on failure
uses: peter-evans/create-or-update-comment@v4
if: failure()
with:
token: ${{ secrets.GIT_PAT }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: |
> **Error**: failed to get build
reactions: "-1"
help:
if: ${{ github.event.client_payload.slash_command.args.unnamed.arg1 == 'help' }}
runs-on: ubuntu-latest
timeout-minutes: 1
steps:
- name: Update comment
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GIT_PAT }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: |
> Command | Description
> --- | ---
> /frontend build | Get build frontend static for all repos
> /frontend build lsf [sha] | Get build frontend static for ${{ github.repository_owner }}/label-studio-frontend only
> /frontend build dm [sha] | Get build frontend static for ${{ github.repository_owner }}/dm2 only
reaction-type: hooray