Bin
2025-12-17 05a69820e0c402b0b33c063d3b922f0a0571cbbb
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
name: 'Follow Merge: Upstream repo sync v2'
 
on:
  workflow_call:
    inputs:
      branch_name:
        required: true
        type: string
  workflow_dispatch:
    inputs:
      branch_name:
        description: 'Branch name'
        required: true
        type: string
 
concurrency:
  group: ${{ github.workflow }}-${{ inputs.branch_name }}
  cancel-in-progress: true
 
env:
  POETRY_VERSION: 2.1.4
  SLACK_CHANNEL_ID: "C02LMULF4NA"
 
jobs:
  sync:
    name: Sync PR
    runs-on: ubuntu-latest
    outputs:
      label-studio-sdk: "${{ fromJSON(steps.upstream-prs.outputs.shas).label-studio-sdk }}"
    steps:
      - uses: hmarr/debug-action@v3.0.0
 
      - name: Add Workflow link to chat ops command comment
        if: github.event.client_payload.github.payload.comment.id && github.event.client_payload.github.payload.repository.full_name
        uses: peter-evans/create-or-update-comment@v5
        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 Actions Hub
        uses: actions/checkout@v6
        with:
          token: ${{ secrets.GIT_PAT }}
          repository: HumanSignal/actions-hub
          path: ./.github/actions-hub
 
      - name: Get Upstream PRs
        uses: ./.github/actions-hub/actions/follow-merge-upstream-prs
        id: upstream-prs
        with:
          branch_name: "${{ inputs.branch_name }}"
          poetry_repositories: "label-studio-sdk"
          infra_repositories: ""
          github_token: "${{ secrets.GIT_PAT }}"
 
      - name: Team details
        id: team_details
        uses: ./.github/actions-hub/actions/team-details
        with:
          jira-server: "${{ vars.JIRA_SERVER }}"
          jira-username: "${{ secrets.JIRA_USERNAME }}"
          jira-token: "${{ secrets.JIRA_TOKEN }}"
          github_token: "${{ secrets.GIT_PAT }}"
          github-username: "${{ steps.upstream-prs.outputs.author_username }}"
        continue-on-error: true
 
      - name: Git Configure
        uses: ./.github/actions-hub/actions/git-configure
        with:
          username: "${{ steps.team_details.outputs.github-username }}"
 
      - name: Find or Create branch
        uses: ./.github/actions-hub/actions/github-find-or-create-branch
        id: get-branch
        with:
          github_token: ${{ secrets.GIT_PAT }}
          base_branch_name: "${{ steps.upstream-prs.outputs.base_branch_name }}"
          branch_name: "${{ steps.upstream-prs.outputs.branch_name }}"
 
      - name: Checkout
        uses: actions/checkout@v6
        with:
          token: ${{ secrets.GIT_PAT }}
          ref: ${{ steps.get-branch.outputs.branch_name }}
          fetch-depth: 0
 
      - name: Checkout Actions Hub
        uses: actions/checkout@v6
        with:
          token: ${{ secrets.GIT_PAT }}
          repository: HumanSignal/actions-hub
          path: ./.github/actions-hub
 
      - name: "Install poetry"
        run: pipx install "poetry==${{ env.POETRY_VERSION }}"
 
      - name: "Set up Python"
        id: setup_python
        uses: actions/setup-python@v6
        with:
          python-version: '3.13'
          cache: 'poetry'
 
      - name: Commit submodule
        shell: bash
        env:
          SDK_SHA: "${{ fromJSON(steps.upstream-prs.outputs.shas).label-studio-sdk }}"
          COMMIT_MESSAGE: "Sync Follow Merge dependencies"
          COMMIT_MESSAGE_WORKFLOW_LINK: "Workflow run: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
        run: |
          set -xeuo pipefail
          
          if [[ -n "${SDK_SHA}" ]]; then
            poetry add "https://github.com/HumanSignal/label-studio-sdk/archive/${SDK_SHA}.zip" --lock
          fi
          
          poetry lock
          
          git diff
          git add -A
          git status -s
          git commit --allow-empty -m "${COMMIT_MESSAGE}" -m "${COMMIT_MESSAGE_WORKFLOW_LINK}"
 
      - name: Git Merge
        id: merge
        continue-on-error: true
        uses: ./.github/actions-hub/actions/git-merge
        with:
          base_branch: ${{ steps.upstream-prs.outputs.base_branch_name }}
          head_branch: ${{ steps.get-branch.outputs.branch_name }}
          our_files: "pyproject.toml poetry.lock web/package.json web/yarn.lock"
 
      - name: Git Push
        uses: ./.github/actions-hub/actions/git-push
 
      - name: Find or Create PR
        uses: ./.github/actions-hub/actions/follow-merge-find-or-create-pull-request
        id: get-pr
        with:
          github_token: ${{ secrets.GIT_PAT }}
          branch_name: "${{ steps.get-branch.outputs.branch_name }}"
          base_branch_name: "${{ steps.upstream-prs.outputs.base_branch_name }}"
          title: "${{ steps.upstream-prs.outputs.title }}"
          upstream_prs_urls: "${{ steps.upstream-prs.outputs.upstream_prs_urls }}"
 
      - name: Add PR Assignees
        uses: ./.github/actions-hub/actions/github-add-pull-request-assignees
        continue-on-error: true
        with:
          github_token: ${{ secrets.GIT_PAT }}
          pullrequest_number: "${{ steps.get-pr.outputs.number }}"
          assignees: "${{ steps.upstream-prs.outputs.assignees }},${{ github.event.client_payload.github.actor }}"
 
      - name: Add PR state Labels
        if: steps.upstream-prs.outputs.status == 'stale'
        uses: ./.github/actions-hub/actions/github-add-pull-request-labels
        continue-on-error: true
        with:
          github_token: ${{ secrets.GIT_PAT }}
          pullrequest_number: "${{ steps.get-pr.outputs.number }}"
          labels: "FM Stale"
 
      - name: Convert to ready for review
        if: steps.upstream-prs.outputs.status == 'merged' || steps.upstream-prs.outputs.status == 'stale'
        id: ready-for-review-pr
        shell: bash
        env:
          GIT_PAT: "${{ secrets.GIT_PAT }}"
        run: |
          echo "$GIT_PAT" | gh auth login --with-token
          gh api graphql -F id='${{ steps.get-pr.outputs.node_id }}' -f query='
            mutation($id: ID!) {
              markPullRequestReadyForReview(input: { pullRequestId: $id }) {
                pullRequest {
                  id
                }
              }
            }
          '
 
      - name: Merge Stale PR
        if: steps.upstream-prs.outputs.status == 'stale'
        continue-on-error: true
        shell: bash
        env:
          GIT_PAT: "${{ secrets.GIT_PAT }}"
          BRANCH_NAME: "origin/${{ steps.get-branch.outputs.branch_name }}"
          BASE_BRANCH_NAME: "origin/${{ steps.upstream-prs.outputs.base_branch_name }}"
          PR_NUMBER: "${{ steps.get-pr.outputs.number }}"
          TITLE: "${{ steps.get-pr.outputs.title }}"
        run: |
          if git diff --quiet "${BASE_BRANCH_NAME}..${BRANCH_NAME}"; then
            echo "No changes detected."
            echo "Merging PR as a Stale."
            echo "$GIT_PAT" | gh auth login --with-token
            gh pr merge "${PR_NUMBER}" --squash --admin --subject "${TITLE} (stale) (#${PR_NUMBER})"
          else
            echo "Changes detected in PR."
          fi
 
      - name: Enable AutoMerge
        if: steps.upstream-prs.outputs.status == 'merged'
        continue-on-error: true
        shell: bash
        env:
          GIT_PAT: ${{ secrets.GIT_PAT }}
        run: |
          echo "$GIT_PAT" | gh auth login --with-token
          gh api graphql -f pull='${{ steps.get-pr.outputs.node_id }}' -f query='
            mutation($pull: ID!) {
              enablePullRequestAutoMerge(input: {pullRequestId: $pull, mergeMethod: SQUASH}) {
                pullRequest {
                  id
                  number
                }
              }
            }'
 
      - name: Close PR
        if: steps.upstream-prs.outputs.status == 'closed'
        continue-on-error: true
        shell: bash
        env:
          GIT_PAT: ${{ secrets.GIT_PAT }}
        run: |
          echo "$GIT_PAT" | gh auth login --with-token
          gh api graphql -f pull='${{ steps.get-pr.outputs.node_id }}' -f query='
            mutation($pull: ID!) {
              closePullRequest(input: {pullRequestId: $pull }) {
                pullRequest {
                  id
                  state
                }
              }
            }'
 
      - name: Send Slack Notification on failure
        if: failure()
        uses: slackapi/slack-github-action@v2.1.1
        env:
          MENTION: "<@${{ steps.team_details.outputs.slack-user-id }}>"
          UPSTREAM_PR: "<${{ steps.upstream-prs.outputs.first_upstream_pr_url }}|upstream pr>, "
          DOWNSTREAM_PR: "<${{ steps.get-pr.outputs.html_url }}|downstream pr>, "
          WORKFLOW: "<https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|workflow>"
        with:
          method: chat.postMessage
          token: ${{ secrets.SLACK_LSE_BOT_TOKEN }}
          payload: |
            channel: "${{ env.SLACK_CHANNEL_ID }}"
            text: >+
              :x: Follow Merge downstream workflow has been failed in <https://github.com/${{ github.repository }}|${{ github.repository }}>.
              [ ${{ steps.upstream-prs.outputs.first_upstream_pr_url && env.UPSTREAM_PR || '' }}${{ steps.get-pr.outputs.html_url && env.DOWNSTREAM_PR || '' }}${{ env.WORKFLOW }} ]
              ${{ steps.team_details.outputs.slack-user-id && env.MENTION || '' }}
 
      - name: Add reaction to chat ops command comment
        if: always() && github.event.client_payload.github.payload.comment.id && github.event.client_payload.github.payload.repository.full_name
        uses: peter-evans/create-or-update-comment@v5
        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 }}
          reactions: ${{ job.status == 'success' && '+1' || '-1' }}