Open PR from csa to main #42
This file contains 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: Open PR from csa to main | |
permissions: | |
contents: write | |
pull-requests: write | |
on: | |
workflow_run: | |
workflows: ["Daily Sync of the csa branch"] | |
types: | |
- completed | |
workflow_dispatch: | |
jobs: | |
open-pr: | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: main | |
- name: Checkout csa | |
run: | | |
git fetch origin csa:csa | |
git reset --hard csa | |
- name: Create Pull Request | |
uses: peter-evans/create-pull-request@v7 | |
with: | |
branch: automation/update_main | |
base: main | |
title: "Sync csa branch with main" | |
body: | | |
This PR syncs the csa branch with the main branch. | |
**PR MUST BE MERGED WITH MERGE COMMIT - ADMIN MUST ENABLE THE OPTION** | |
token: ${{secrets.GITHUB_TOKEN}} | |
labels: | |
changing-submodules-on-purpose, sl-require-admin-action | |
# The next step is necessary to force the CI to be executed when a PR is opened by the github-bot. | |
# The PR event isn't triggered when the bot opens the PR and as such doesn't trigger the workflows that use the event as their trigger. | |
# By closing and opening the PR, it forces the PR event to be triggered. | |
- name: Check if PR is already closed and reopen if necessary | |
run: | | |
PR_NUMBER=$(gh pr list --repo ${{ github.repository }} --state open --head automation/update_main --json number --jq '.[0].number') | |
if [ -z "$PR_NUMBER" ]; then | |
echo "PR not found." | |
exit 1 | |
fi | |
LABELS=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json labels --jq '.labels[].name') | |
if ! echo "$LABELS" | grep -q "sl-automation-triggered"; then | |
gh pr close $PR_NUMBER --repo ${{ github.repository }} | |
gh pr reopen $PR_NUMBER --repo ${{ github.repository }} | |
fi | |
env: | |
GITHUB_TOKEN: ${{secrets.WORKFLOW_TOKEN}} |