Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: DIA-1862: Revert .github/workflows #408

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/fm-command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: "/fm command"

on:
repository_dispatch:
types: [ fm-command ]

concurrency:
group: ${{ github.workflow }}-${{ github.event.client_payload.github.payload.issue.number }}-${{ github.event.client_payload.slash_command.command }}-${{ github.event.client_payload.slash_command.args.unnamed.arg1 || github.event.client_payload.slash_command.args.all }}

jobs:
sync:
name: "Update: Update Feature Flags"
if: github.event.client_payload.slash_command.args.unnamed.arg1 == 'sync'
uses: ./.github/workflows/follow-merge-upstream-repo-sync-v2.yml
with:
branch_name: ${{ github.event.client_payload.pull_request.head.ref }}
secrets: inherit

help:
if: ${{ github.event.client_payload.slash_command.args.unnamed.arg1 == 'help' || !contains(fromJson('["sync"]'), github.event.client_payload.slash_command.args.unnamed.arg1) }}
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
> --- | ---
> /fm sync | Sync upstream prs and merge with pull request base
reaction-type: hooray
277 changes: 277 additions & 0 deletions .github/workflows/follow-merge-upstream-repo-sync-v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
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:
NODE: "18"
YARN: "1.22"

jobs:
sync:
name: Sync PR
runs-on: ubuntu-latest
outputs:
adala: "${{ steps.upstream-prs.outputs.adala }}"
label-studio-query-vectordb: "${{ steps.upstream-prs.outputs.label-studio-query-vectordb }}"
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: Find or Create branch
uses: ./.github/actions-hub/actions/github-find-or-create-branch
id: get-branch
with:
github_token: ${{ secrets.GIT_PAT }}
branch_name: "${{ inputs.branch_name }}"

- name: Checkout label-studio-client-generator
uses: actions/checkout@v4
with:
token: ${{ secrets.GIT_PAT }}
repository: HumanSignal/label-studio-client-generator
ref: ${{ steps.get-branch.outputs.branch_name }}
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: Get Upstream PRs
id: upstream-prs
uses: actions/github-script@v7
env:
BRANCH_NAME: ${{ inputs.branch_name }}
with:
github-token: ${{ secrets.GIT_PAT }}
script: |
const { repo, owner } = context.repo;
const branch_name = process.env.BRANCH_NAME;
const pyProjectPath = "pyproject.toml";
const repos = ["label-studio-client-generator"];
const repos_infra = [];
const base_branch_name = context.repo.default_branch;

let shas = {};

// GET UPSTREAM PRS
let upstream_pulls = [];
for (const repo of repos.concat(repos_infra)) {
const {data: pulls} = await github.rest.pulls.list({
owner,
repo,
state: "all",
head: `${owner}:${branch_name}`,
});
const first_open_pull = pulls.find(e => e.state === 'open');
const pull = first_open_pull || pulls[0];
if (pull) {
core.info(`PRs found for ${repo} ${pull.html_url} ${pull.merged_at ? 'merged' : pull.state} ${pull.merged_at ? pull.merge_commit_sha : pull.head.sha}`)
upstream_pulls.push(pull);
if (pull.merged_at) {
shas[repo] = pull.merge_commit_sha;
} else if (pull.state === 'open') {
shas[repo] = pull.head.sha;
}
} else {
core.notice(`No open upstream PRs found for ${repo}`)
}
}

for (const [key, value] of Object.entries(shas)) {
core.setOutput(key, value);
}

core.info(`Base branch name ${base_branch_name}`);
core.setOutput('base_branch_name', base_branch_name);

if (upstream_pulls.length > 0) {
core.info(`Title ${upstream_pulls[0].title}`);
core.setOutput('title', upstream_pulls[0].title);
}

const upstream_prs_urls = upstream_pulls.map(e => e.html_url).join(',');
core.info(`Upstream PRs URLs ${upstream_prs_urls}`);
core.setOutput('upstream_prs_urls', upstream_prs_urls);

let assignees = [];
for (const pull of upstream_pulls) {
if (pull.user) assignees.push(pull.user.login);
if (pull.assignee) assignees.push(pull.assignee.login);
assignees.concat(pull.assignees.map(e => e.name));
}
assignees = assignees.filter(x => x !== 'robot-ci-heartex');
core.info(`Assignees ${assignees.join(',')}`);
core.setOutput('assignees', assignees.join(','));

if (assignees.length > 0) {
const author_username = assignees[0];
core.info(`Author username ${author_username}`);
core.setOutput('author_username', author_username);
}

let status = "open"
if (upstream_pulls.every(p => p.merged_at)) {
status = 'merged';
} else if (upstream_pulls.every(p => p.closed_at)) {
status = 'closed';
}
core.info(`Status: ${status}`);
core.setOutput("status", status);

- name: Git Configure
uses: ./.github/actions-hub/actions/git-configure
with:
username: ${{ steps.upstream-prs.outputs.author_username }}

- 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 }}"
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: 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' }}
Loading