Skip to content

Commit ab42dd4

Browse files
authored
Merge pull request #8 from OpenSlides/feature/add-automation
2 parents d2499e9 + 5d6af1a commit ab42dd4

8 files changed

+208
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Cherry pick staging PRs merged into main
2+
on:
3+
pull_request_target:
4+
types:
5+
- closed
6+
branches:
7+
- "main"
8+
jobs:
9+
create-pr-for-staging:
10+
if: |
11+
github.event.pull_request.merged == true &&
12+
contains(github.event.pull_request.labels.*.name, 'staging')
13+
name: Create PR against staging branch
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout main
17+
uses: actions/checkout@v6
18+
with:
19+
ref: main
20+
fetch-depth: 2
21+
22+
- name: Fetch and checkout latest staging branch
23+
run: |
24+
branch=$(git ls-remote --heads origin 'staging/*' | awk 'gsub(".*refs/heads/","")' | sort -V | tail -1)
25+
git fetch origin $branch
26+
git checkout $branch
27+
28+
- name: Set git credentials
29+
run: |
30+
git config --global user.name openslides-automation
31+
git config --global user.email [email protected]
32+
33+
- name: Cherry-pick new commit
34+
id: cherry-pick
35+
run: |
36+
git fetch origin
37+
# -m 1 to also be able to cherry-pick merge commits
38+
git cherry-pick -m 1 ${{ github.sha }} || {
39+
echo "error=1" >> $GITHUB_OUTPUT
40+
git add .
41+
git cherry-pick --continue
42+
}
43+
44+
- name: Generate access token
45+
uses: actions/create-github-app-token@v2
46+
id: generate-token
47+
with:
48+
app-id: ${{ secrets.AUTOMATION_APP_ID }}
49+
private-key: ${{ secrets.AUTOMATION_APP_PRIVATE_KEY }}
50+
51+
- name: Create or update PR
52+
uses: peter-evans/create-pull-request@v8
53+
with:
54+
token: ${{ steps.generate-token.outputs.token }}
55+
branch: apply/commit-${{ github.sha }}
56+
delete-branch: true
57+
title: "[Cherry-Pick] ${{ github.event.pull_request.title }}"
58+
body: "Triggered by commit [${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }})\n\n${{ steps.cherry-pick.outputs.error && 'There were conflicts during the cherry-pick. These were commited without any resolving. Please resolve them manually and push the result to this branch before merging.' || 'The cherry-pick was successful without any conflicts. You should be able to simply merge this PR.' }}"
59+
reviewers: ${{ github.event.pull_request.user.login }}
60+
assignees: ${{ github.event.pull_request.user.login }}
61+
labels: picked-to-staging
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Close issues on feature branch merge
2+
on:
3+
pull_request_target:
4+
types:
5+
- closed
6+
branches:
7+
- "feature/*"
8+
jobs:
9+
close-issue:
10+
runs-on: ubuntu-latest
11+
if: github.event.pull_request.merged
12+
steps:
13+
- name: Generate access token
14+
uses: actions/create-github-app-token@v2
15+
id: generate-token
16+
with:
17+
app-id: ${{ secrets.AUTOMATION_APP_ID }}
18+
private-key: ${{ secrets.AUTOMATION_APP_PRIVATE_KEY }}
19+
20+
- uses: octokit/graphql-action@v3
21+
id: get-issues
22+
env:
23+
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
24+
with:
25+
query: |
26+
query getLinkedIssues($owner: String!, $name: String!, $number: Int!) {
27+
repository(owner: $owner, name: $name) {
28+
pullRequest(number: $number) {
29+
closingIssuesReferences(first: 100) {
30+
nodes {
31+
number
32+
repository {
33+
nameWithOwner
34+
}
35+
}
36+
}
37+
}
38+
}
39+
}
40+
variables: |
41+
owner: ${{ github.repository_owner }}
42+
name: ${{ github.event.repository.name }}
43+
number: ${{ github.event.pull_request.number }}
44+
45+
- name: Close issues
46+
env:
47+
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
48+
run: |
49+
issue_data="$(echo '${{ steps.get-issues.outputs.data }}' | jq -r '.repository.pullRequest.closingIssuesReferences.nodes[] | [.number,.repository.nameWithOwner] | @tsv')"
50+
echo "$issue_data" | grep -v "^$" | while read number nameWithOwner; do
51+
gh issue close "$number" -r "$nameWithOwner"
52+
done
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Project automation
2+
on:
3+
issues:
4+
types:
5+
- closed
6+
jobs:
7+
issue_closed:
8+
name: Issue closed
9+
uses: ./.github/workflows/project-automation.yml
10+
secrets: inherit
11+
with:
12+
resource_node_id: ${{ github.event.issue.node_id }}
13+
status_value: "Done"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Project automation
2+
on:
3+
issues:
4+
types:
5+
- opened
6+
- reopened
7+
jobs:
8+
issue_opened:
9+
name: Issue opened
10+
uses: ./.github/workflows/project-automation.yml
11+
secrets: inherit
12+
with:
13+
resource_node_id: ${{ github.event.issue.node_id }}
14+
status_value: "Backlog"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Project automation
2+
on:
3+
pull_request_target:
4+
types:
5+
- closed
6+
jobs:
7+
pull_request_closed:
8+
name: Pull request closed
9+
uses: ./.github/workflows/project-automation.yml
10+
secrets: inherit
11+
with:
12+
resource_node_id: ${{ github.event.pull_request.node_id }}
13+
status_value: "Done"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Project automation
2+
on:
3+
pull_request_target:
4+
types:
5+
- opened
6+
- reopened
7+
jobs:
8+
pull_request_opened:
9+
name: Pull request opened
10+
uses: ./.github/workflows/project-automation.yml
11+
secrets: inherit
12+
with:
13+
resource_node_id: ${{ github.event.pull_request.node_id }}
14+
status_value: "Work in progress"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Project automation
2+
on:
3+
pull_request_target:
4+
types:
5+
- review_requested
6+
jobs:
7+
pull_request_review_requested:
8+
name: Pull request review requested
9+
uses: ./.github/workflows/project-automation.yml
10+
secrets: inherit
11+
with:
12+
resource_node_id: ${{ github.event.pull_request.node_id }}
13+
status_value: "Review in progress"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Project automation
2+
on:
3+
workflow_call:
4+
inputs:
5+
resource_node_id:
6+
required: true
7+
type: string
8+
status_value:
9+
required: true
10+
type: string
11+
secrets:
12+
AUTOMATION_APP_ID:
13+
required: true
14+
AUTOMATION_APP_PRIVATE_KEY:
15+
required: true
16+
jobs:
17+
workflow_call:
18+
name: Set status
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: leonsteinhaeuser/[email protected]
22+
with:
23+
gh_app_ID: ${{ secrets.AUTOMATION_APP_ID }}
24+
gh_app_secret_key: ${{ secrets.AUTOMATION_APP_PRIVATE_KEY }}
25+
organization: OpenSlides
26+
project_id: 2
27+
resource_node_id: ${{ inputs.resource_node_id }}
28+
status_value: ${{ inputs.status_value }}

0 commit comments

Comments
 (0)