Skip to content

Commit

Permalink
Merge branch 'master' into fb-converter-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
makseq authored Aug 13, 2024
2 parents 4bf4c37 + 3ac8f15 commit 6acdde7
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.github/ @farioas
.github/ @HumanSignal/devops
37 changes: 37 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: "CodeQL"

on:
push:
branches: [ "master", "release/**" ]
schedule:
- cron: '35 22 * * 0'

jobs:
analyze:
name: Analyze
runs-on: 'ubuntu-latest'
timeout-minutes: 45
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'python' ]

steps:
- name: Checkout repository
uses: actions/checkout@v4.1.1

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
#config-file: ./.github/codeql/codeql-config.yaml

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
103 changes: 103 additions & 0 deletions .github/workflows/jira-command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: "/jira command"

on:
repository_dispatch:
types: [ jira-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:
create:
if: ${{ github.event.client_payload.slash_command.args.unnamed.arg1 == 'create' }}
runs-on: ubuntu-latest
timeout-minutes: 3
steps:
- uses: hmarr/debug-action@v3.0.0

- 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: Check user's membership
uses: actions/github-script@v7
id: check-membership
env:
ACTOR: ${{ github.actor }}
with:
github-token: ${{ secrets.GIT_PAT }}
script: |
const { repo, owner } = context.repo;
const actor = process.env.ACTOR;
const { data: membership } = await github.rest.orgs.getMembershipForUser({
org: owner,
username: actor,
});
if (membership.state != "active") {
const error = `Unfortunately you don't have membership in ${owner} organization, Jira Issue was not created`;
core.setOutput("error", error);
core.setFailed(error);
}
- name: Checkout Actions Hub
uses: actions/checkout@v4
with:
token: ${{ secrets.GIT_PAT }}
repository: HumanSignal/actions-hub
path: ./.github/actions-hub

- name: Jira Create Issue
id: jira-create-issue
uses: ./.github/actions-hub/actions/jira-create-issue
with:
jira_server: ${{ vars.JIRA_SERVER }}
jira_username: ${{ secrets.JIRA_USERNAME }}
jira_token: ${{ secrets.JIRA_TOKEN }}
summary: ${{ github.event.client_payload.github.payload.issue.title }}
description: ${{ github.event.client_payload.github.payload.issue.body }}
project: ${{ github.event.client_payload.slash_command.args.unnamed.arg3 || 'TRIAG' }}
type: ${{ github.event.client_payload.slash_command.args.unnamed.arg2 || 'task' }}

- name: Add reaction to command comment on success
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: |
> Jira issue [${{ steps.jira-create-issue.outputs.key }}](${{ steps.jira-create-issue.outputs.link }}) is created
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 execute "${{ github.event.client_payload.slash_command.args.unnamed.arg1 }}" command
> ${{ steps.check-membership.outputs.error }}
reactions: "-1"

help:
if: github.event.client_payload.slash_command.args.unnamed.arg1 == 'help' || !contains(fromJson('["create"]'), 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
> --- | ---
> /jira create [task|bug|story] `PROJECT` | Create a Jira issue in project `PROJECT`
reaction-type: hooray
6 changes: 3 additions & 3 deletions .github/workflows/pr-labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ jobs:
name: "PR label validator"
runs-on: ubuntu-latest
steps:
- uses: hmarr/debug-action@v2.1.0
- uses: thehanimo/pr-title-checker@v1.4.0
- uses: hmarr/debug-action@v3.0.0
- uses: thehanimo/pr-title-checker@v1.4.2
name: "Validate PR's title"
with:
GITHUB_TOKEN: ${{ secrets.GIT_PAT }}
pass_on_octokit_error: false
configuration_path: ".github/pr-title-checker-config.json"
- uses: release-drafter/release-drafter@v5.24.0
- uses: release-drafter/release-drafter@v6.0.0
name: "Set PR's label based on title"
with:
disable-releaser: true
Expand Down
79 changes: 79 additions & 0 deletions .github/workflows/slash-command-dispatch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Slash Command Dispatch
on:
issue_comment:
types: [created]

env:
commands_list: |
jira
issue_commands_list: |
jira
jobs:
slashCommandDispatch:
if: startsWith(github.event.comment.body, '/')
timeout-minutes: 1
runs-on: ubuntu-latest
steps:
- uses: hmarr/debug-action@v3.0.0

- name: 'Validate command'
id: determine_command
uses: actions/github-script@v7
env:
COMMANDS_LIST: ${{ env.commands_list }}
ISSUE_COMMANDS_LIST: ${{ env.issue_commands_list }}
with:
github-token: ${{ secrets.GIT_PAT }}
script: |
const body = context.payload.comment.body.toLowerCase().trim()
const commands_list = process.env.COMMANDS_LIST.split("\n")
const issue_commands_list = process.env.ISSUE_COMMANDS_LIST.split("\n")
console.log("Detected PR comment: " + body)
console.log("Commands list: " + commands_list)
console.log("Issue commands list: " + issue_commands_list)
commandArray = body.split(/\s+/)
const contextCommand = commandArray[0].split('/')[1].trim();
console.log("contextCommand: " + contextCommand)
core.setOutput('command_state', 'known')
core.setOutput('is_issue_command', 'false')
if (! commands_list.includes(contextCommand)) {
core.setOutput('command_state', 'unknown')
core.setOutput('command', contextCommand)
}
if (issue_commands_list.includes(contextCommand)) {
core.setOutput('is_issue_command', 'true')
}
- name: Slash Command Dispatch for Issues
id: scd_issues
if: ${{ steps.determine_command.outputs.command_state != 'unknown' && steps.determine_command.outputs.is_issue_command == 'true' }}
uses: peter-evans/slash-command-dispatch@v4
with:
token: ${{ secrets.GIT_PAT }}
reaction-token: ${{ secrets.GIT_PAT }}
issue-type: "issue"
reactions: true
commands: ${{ env.issue_commands_list }}

- name: Slash Command Dispatch for PRs
id: scd_prs
if: ${{ steps.determine_command.outputs.command_state != 'unknown' && steps.determine_command.outputs.is_issue_command != 'true' }}
uses: peter-evans/slash-command-dispatch@v4
with:
token: ${{ secrets.GIT_PAT }}
reaction-token: ${{ secrets.GIT_PAT }}
issue-type: "pull-request"
reactions: true
commands: ${{ env.commands_list }}

- name: Edit comment with error message
if: ${{ steps.determine_command.outputs.command_state == 'unknown' }}
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ github.event.comment.id }}
body: |
> '/${{ steps.determine_command.outputs.command }}' is an unknown command.
> See '/help'
reactions: eyes, confused
41 changes: 26 additions & 15 deletions .github/workflows/sync-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@ concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}

env:
DOWNSTREAM_REPO: label-studio-enterprise
DOWNSTREAM_REPOSITORY: "label-studio-enterprise"
DOWNSTREAM_EVENT_TYPE: "upstream_repo_update"

jobs:
sync:
name: "Sync"
if: startsWith(github.head_ref, 'fb-')
runs-on: ubuntu-latest
steps:
- uses: hmarr/debug-action@v2.1.0
- uses: hmarr/debug-action@v3.0.0

- name: Check user's membership
uses: actions/github-script@v6
uses: actions/github-script@v7
id: check-membership
with:
github-token: ${{ secrets.GIT_PAT }}
Expand All @@ -44,7 +45,7 @@ jobs:
- name: Notify user on failure
if: steps.check-membership.outputs.result == 'false'
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GIT_PAT }}
script: |
Expand All @@ -56,26 +57,36 @@ jobs:
body: [
'Hi @${{ github.actor }}!',
'',
`Unfortunately you don't have membership in ${owner} organization, your PR wasn't synced with ${owner}/${{ env.DOWNSTREAM_REPO }}.`
`Unfortunately you don't have membership in ${owner} organization, your PR wasn't synced with ${owner}/${{ env.DOWNSTREAM_REPOSITORY }}.`
].join('\n')
});
- name: Sync PR
uses: actions/github-script@v6
uses: actions/github-script@v7
if: steps.check-membership.outputs.result == 'true'
id: sync-pr
env:
TITLE: ${{ github.event.pull_request.title }}
HEAD_REF: ${{ github.head_ref }}
BASE_REF: ${{ github.base_ref }}
PR_HEAD_REPOSITORY: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
DOWNSTREAM_REPOSITORY: ${{ env.DOWNSTREAM_REPOSITORY }}
DOWNSTREAM_EVENT_TYPE: ${{ env.DOWNSTREAM_EVENT_TYPE }}
with:
github-token: ${{ secrets.GIT_PAT }}
script: |
const { repo, owner } = context.repo;
const [pr_owner, pr_repo] = '${{ github.event.pull_request.head.repo.full_name || github.repository }}'.split('/');
let event_action = '${{ github.event.action }}'
let commit_sha = '${{ github.event.pull_request.head.sha }}'
const pr_head_repository = process.env.PR_HEAD_REPOSITORY;
const downstream_repository = process.env.DOWNSTREAM_REPOSITORY;
const downstream_event_type = process.env.DOWNSTREAM_EVENT_TYPE;
const [pr_owner, pr_repo] = pr_head_repository.split('/');
const head_ref = process.env.HEAD_REF;
const base_ref = process.env.BASE_REF;
let event_action = '${{ github.event.action }}';
let commit_sha = '${{ github.event.pull_request.head.sha }}';
if (${{ github.event.pull_request.merged }}) {
event_action = 'merged'
commit_sha = '${{ github.sha }}'
event_action = 'merged';
commit_sha = '${{ github.sha }}';
}
const getCommitResponse = await github.rest.repos.getCommit({
owner: pr_owner,
Expand All @@ -84,11 +95,11 @@ jobs:
});
const result = await github.rest.repos.createDispatchEvent({
owner: owner,
repo: '${{ env.DOWNSTREAM_REPO }}',
event_type: 'upstream_repo_update',
repo: downstream_repository,
event_type: downstream_event_type,
client_payload: {
branch_name: '${{ github.head_ref }}',
base_branch_name: '${{ github.base_ref }}',
branch_name: head_ref,
base_branch_name: base_ref,
repo_name: '${{ github.repository }}',
commit_sha : commit_sha,
title: process.env.TITLE,
Expand Down
Loading

0 comments on commit 6acdde7

Please sign in to comment.