diff --git a/.github/workflows/cherry-pick-staging.yml b/.github/workflows/cherry-pick-staging.yml new file mode 100644 index 0000000..6c1864f --- /dev/null +++ b/.github/workflows/cherry-pick-staging.yml @@ -0,0 +1,61 @@ +name: Cherry pick staging PRs merged into main +on: + pull_request_target: + types: + - closed + branches: + - "main" +jobs: + create-pr-for-staging: + if: | + github.event.pull_request.merged == true && + contains(github.event.pull_request.labels.*.name, 'staging') + name: Create PR against staging branch + runs-on: ubuntu-latest + steps: + - name: Checkout main + uses: actions/checkout@v6 + with: + ref: main + fetch-depth: 2 + + - name: Fetch and checkout latest staging branch + run: | + branch=$(git ls-remote --heads origin 'staging/*' | awk 'gsub(".*refs/heads/","")' | sort -V | tail -1) + git fetch origin $branch + git checkout $branch + + - name: Set git credentials + run: | + git config --global user.name openslides-automation + git config --global user.email openslides-automation@users.noreply.github.com + + - name: Cherry-pick new commit + id: cherry-pick + run: | + git fetch origin + # -m 1 to also be able to cherry-pick merge commits + git cherry-pick -m 1 ${{ github.sha }} || { + echo "error=1" >> $GITHUB_OUTPUT + git add . + git cherry-pick --continue + } + + - name: Generate access token + uses: actions/create-github-app-token@v2 + id: generate-token + with: + app-id: ${{ secrets.AUTOMATION_APP_ID }} + private-key: ${{ secrets.AUTOMATION_APP_PRIVATE_KEY }} + + - name: Create or update PR + uses: peter-evans/create-pull-request@v8 + with: + token: ${{ steps.generate-token.outputs.token }} + branch: apply/commit-${{ github.sha }} + delete-branch: true + title: "[Cherry-Pick] ${{ github.event.pull_request.title }}" + 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.' }}" + reviewers: ${{ github.event.pull_request.user.login }} + assignees: ${{ github.event.pull_request.user.login }} + labels: picked-to-staging \ No newline at end of file diff --git a/.github/workflows/close-issue-on-feature-merge.yml b/.github/workflows/close-issue-on-feature-merge.yml new file mode 100644 index 0000000..c92117e --- /dev/null +++ b/.github/workflows/close-issue-on-feature-merge.yml @@ -0,0 +1,52 @@ +name: Close issues on feature branch merge +on: + pull_request_target: + types: + - closed + branches: + - "feature/*" +jobs: + close-issue: + runs-on: ubuntu-latest + if: github.event.pull_request.merged + steps: + - name: Generate access token + uses: actions/create-github-app-token@v2 + id: generate-token + with: + app-id: ${{ secrets.AUTOMATION_APP_ID }} + private-key: ${{ secrets.AUTOMATION_APP_PRIVATE_KEY }} + + - uses: octokit/graphql-action@v3 + id: get-issues + env: + GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }} + with: + query: | + query getLinkedIssues($owner: String!, $name: String!, $number: Int!) { + repository(owner: $owner, name: $name) { + pullRequest(number: $number) { + closingIssuesReferences(first: 100) { + nodes { + number + repository { + nameWithOwner + } + } + } + } + } + } + variables: | + owner: ${{ github.repository_owner }} + name: ${{ github.event.repository.name }} + number: ${{ github.event.pull_request.number }} + + - name: Close issues + env: + GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }} + run: | + issue_data="$(echo '${{ steps.get-issues.outputs.data }}' | jq -r '.repository.pullRequest.closingIssuesReferences.nodes[] | [.number,.repository.nameWithOwner] | @tsv')" + echo "$issue_data" | grep -v "^$" | while read number nameWithOwner; do + gh issue close "$number" -r "$nameWithOwner" + done \ No newline at end of file diff --git a/.github/workflows/project-automation-issue-closed.yml b/.github/workflows/project-automation-issue-closed.yml new file mode 100644 index 0000000..386e8f6 --- /dev/null +++ b/.github/workflows/project-automation-issue-closed.yml @@ -0,0 +1,13 @@ +name: Project automation +on: + issues: + types: + - closed +jobs: + issue_closed: + name: Issue closed + uses: ./.github/workflows/project-automation.yml + secrets: inherit + with: + resource_node_id: ${{ github.event.issue.node_id }} + status_value: "Done" \ No newline at end of file diff --git a/.github/workflows/project-automation-issue-opened.yml b/.github/workflows/project-automation-issue-opened.yml new file mode 100644 index 0000000..04331e1 --- /dev/null +++ b/.github/workflows/project-automation-issue-opened.yml @@ -0,0 +1,14 @@ +name: Project automation +on: + issues: + types: + - opened + - reopened +jobs: + issue_opened: + name: Issue opened + uses: ./.github/workflows/project-automation.yml + secrets: inherit + with: + resource_node_id: ${{ github.event.issue.node_id }} + status_value: "Backlog" \ No newline at end of file diff --git a/.github/workflows/project-automation-pr-closed.yml b/.github/workflows/project-automation-pr-closed.yml new file mode 100644 index 0000000..b3fca22 --- /dev/null +++ b/.github/workflows/project-automation-pr-closed.yml @@ -0,0 +1,13 @@ +name: Project automation +on: + pull_request_target: + types: + - closed +jobs: + pull_request_closed: + name: Pull request closed + uses: ./.github/workflows/project-automation.yml + secrets: inherit + with: + resource_node_id: ${{ github.event.pull_request.node_id }} + status_value: "Done" \ No newline at end of file diff --git a/.github/workflows/project-automation-pr-opened.yml b/.github/workflows/project-automation-pr-opened.yml new file mode 100644 index 0000000..90a704e --- /dev/null +++ b/.github/workflows/project-automation-pr-opened.yml @@ -0,0 +1,14 @@ +name: Project automation +on: + pull_request_target: + types: + - opened + - reopened +jobs: + pull_request_opened: + name: Pull request opened + uses: ./.github/workflows/project-automation.yml + secrets: inherit + with: + resource_node_id: ${{ github.event.pull_request.node_id }} + status_value: "Work in progress" \ No newline at end of file diff --git a/.github/workflows/project-automation-pr-review-requested.yml b/.github/workflows/project-automation-pr-review-requested.yml new file mode 100644 index 0000000..c2d4529 --- /dev/null +++ b/.github/workflows/project-automation-pr-review-requested.yml @@ -0,0 +1,13 @@ +name: Project automation +on: + pull_request_target: + types: + - review_requested +jobs: + pull_request_review_requested: + name: Pull request review requested + uses: ./.github/workflows/project-automation.yml + secrets: inherit + with: + resource_node_id: ${{ github.event.pull_request.node_id }} + status_value: "Review in progress" \ No newline at end of file diff --git a/.github/workflows/project-automation.yml b/.github/workflows/project-automation.yml new file mode 100644 index 0000000..a733bac --- /dev/null +++ b/.github/workflows/project-automation.yml @@ -0,0 +1,28 @@ +name: Project automation +on: + workflow_call: + inputs: + resource_node_id: + required: true + type: string + status_value: + required: true + type: string + secrets: + AUTOMATION_APP_ID: + required: true + AUTOMATION_APP_PRIVATE_KEY: + required: true +jobs: + workflow_call: + name: Set status + runs-on: ubuntu-latest + steps: + - uses: leonsteinhaeuser/project-beta-automations@v2.2.1 + with: + gh_app_ID: ${{ secrets.AUTOMATION_APP_ID }} + gh_app_secret_key: ${{ secrets.AUTOMATION_APP_PRIVATE_KEY }} + organization: OpenSlides + project_id: 2 + resource_node_id: ${{ inputs.resource_node_id }} + status_value: ${{ inputs.status_value }} \ No newline at end of file