Follow Merge: Upstream repo sync v2 #36
This file contains hidden or 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: '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 | |
jobs: | |
sync: | |
name: Sync PR | |
runs-on: ubuntu-latest | |
outputs: | |
label-studio-client-generator: "${{ fromJSON(steps.upstream-prs.outputs.shas).label-studio-client-generator }}" | |
steps: | |
- uses: hmarr/[email protected] | |
- 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@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 Actions Hub | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GIT_PAT }} | |
repository: HumanSignal/actions-hub | |
path: ./.github/actions-hub | |
- 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 }}" | |
continue-on-error: true | |
- name: Git Configure | |
uses: ./.github/actions-hub/actions/git-configure | |
with: | |
username: "${{ steps.team_details.outputs.github-username }}" | |
- name: Get Upstream PRs | |
uses: ./.github/actions-hub/actions/follow-merge-upstream-prs | |
id: upstream-prs | |
with: | |
branch_name: "${{ inputs.branch_name }}" | |
poetry_repositories: "" | |
infra_repositories: "label-studio-client-generator" | |
github_token: "${{ secrets.GIT_PAT }}" | |
- 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 label-studio-client-generator | |
if: fromJSON(steps.upstream-prs.outputs.shas).label-studio-client-generator | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GIT_PAT }} | |
repository: HumanSignal/label-studio-client-generator | |
ref: "${{ fromJSON(steps.upstream-prs.outputs.shas).label-studio-client-generator }}" | |
fetch-depth: 0 | |
- name: Checkout Actions Hub | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GIT_PAT }} | |
repository: HumanSignal/actions-hub | |
path: ./.github/actions-hub | |
- name: Setup node | |
uses: actions/setup-node@v4 | |
- name: Install Fern | |
run: npm install -g fern-api@latest | |
- name: Download Fern | |
run: npm install -g fern-api@latest | |
- name: Set Fern Generator Branch and Mode | |
env: | |
BRANCH_NAME: "${{ steps.get-branch.outputs.branch_name }}" | |
FERN_GENERATOR_PATH: "fern/generators.yml" | |
run: | | |
yq e --inplace ".groups.python-sdk-staging.generators[0].github.branch |= \"${BRANCH_NAME}\"" "${FERN_GENERATOR_PATH}" | |
yq e --inplace ".groups.python-sdk-staging.generators[0].github.mode |= \"push\"" "${FERN_GENERATOR_PATH}" | |
cat "${FERN_GENERATOR_PATH}" | |
- name: Check Fern API is valid | |
run: fern check | |
- name: Generate Python SDK | |
env: | |
FERN_TOKEN: ${{ secrets.FERN_TOKEN }} | |
working-directory: "${{ env.UPSTREAM_REPO_WORKDIR }}" | |
run: fern generate --group python-sdk-staging --log-level debug | |
- 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 | |
if: steps.upstream-prs.outputs.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 }}" | |
- 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' | |
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: 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: Notify on failure | |
# uses: ./.github/actions-hub/actions/github-create-comment | |
# if: failure() | |
# with: | |
# github_token: ${{ secrets.GIT_PAT }} | |
# repository: "${{ steps.fm.outputs.repo_name }}" | |
# issue_number: "${{ steps.fm.outputs.pr_number }}" | |
# body: | | |
# Follow Merge downstream workflow has been failed. | |
# > [Workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) | |
- 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@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 }} | |
reactions: ${{ job.status == 'success' && '+1' || '-1' }} |