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

New workflow frameworkPR for automatic submodule PR merging #259

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
86 changes: 86 additions & 0 deletions .github/actions/automerge/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: "Automatic PR checks and merge"
description: "Checks if a particular branch and pull request exist in a repository"
inputs:
branch:
description: "Branch to checkout"
required: true
repository:
description: "Repository"
required: true
token:
description: "Authentification token"
required: true

runs:
using: "composite"
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
repository: ${{ inputs.repository }}
path: repository
- name: Check repository branch
id: repositoryBranch
run: |
cd repository
var=$(git ls-remote --heads origin ${{ inputs.branch }})
if [[ -z $var ]]; then
echo "Branch "${{ inputs.branch }}" not found in " ${{ inputs.repository }}
echo "exist=false" >> $GITHUB_OUTPUT
else
echo "Branch "${{ inputs.branch }}" found in " ${{ inputs.repository }}
git fetch
git checkout ${{ inputs.branch }}
git pull
echo "exist=true" >> $GITHUB_OUTPUT
fi
shell: bash
- name: Check PR
id: PRCheck
if: steps.repositoryBranch.outputs.exist == 'true'
run: |
cd repository
#Check PR
gh auth status
gh pr view
prurl=$(gh pr view --json url -t '{{ .url }}')
echo "prurl=$prurl" >> $GITHUB_OUTPUT
mergeStateStatus=$(gh pr view --json mergeStateStatus -t '{{ .mergeStateStatus }}')
echo "MergeStateStatus " $mergeStateStatus
echo "mergeStateStatus=$mergeStateStatus" >> $GITHUB_OUTPUT
prState=$(gh pr view --json state -t '{{ .state }}')
echo "prState=$prState" >> $GITHUB_OUTPUT
echo "PullRequestState " $prState
review=$(gh pr view --json reviewDecision -t '{{ .reviewDecision }}')
echo "review=$review" >> $GITHUB_OUTPUT
echo "Review decision " $review
if [[ $prState == "MERGED" ]]; then
echo "PR already merged"
elif [[ $review == "APPROVED" ]]; then
echo "PR is approved and mergeStateStatus is " $mergeStateStatus
else
echo "No valid PR found for branch " ${{ inputs.branch }} " in " ${{ inputs.repository }} " merge is not allowed"
exit 1
fi
env:
GITHUB_TOKEN: ${{ inputs.token }}
shell: bash
- name: Print outputs
if: steps.repositoryBranch.outputs.exist == 'true'
run: |
echo "Merge status " ${{ steps.PRCheck.outputs.mergeStateStatus }}
echo "PR REVIEW " ${{ steps.PRCheck.outputs.review }}
echo "PR url " ${{ steps.PRCheck.outputs.prurl }}
echo "PR state " ${{ steps.PRCheck.outputs.prState }}
shell: bash
- name: Merge PR
if: (github.event.action == 'closed' && github.event.pull_request.merged == true && steps.PRCheck.outputs.review == 'APPROVED' && steps.PRCheck.outputs.prState != 'MERGED')
run: |
cd repository
gh auth status
echo "actor " ${{ github.actor }}
gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{ steps.PRCheck.outputs.prurl }}
GITHUB_TOKEN: ${{ inputs.token }}
shell: bash
33 changes: 33 additions & 0 deletions .github/workflows/frameworkPR.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Check on submodules PR

on:
pull_request:
branches: [ "master" ]
types: [ "opened", "reopened", "created", "closed", "synchronize"]

workflow_dispatch:

permissions: write-all

env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}

defaults:
run:
shell: bash

jobs:
framework-pr:
strategy:
matrix:
submodules: ["rest-for-physics/rawlib", "rest-for-physics/detectorlib", "rest-for-physics/geant4lib","rest-for-physics/tracklib", "rest-for-physics/connectorslib", "rest-for-physics/axionlib", "rest-for-physics/legacylib", "rest-for-physics/restG4"]
runs-on: ubuntu-latest
if: github.head_ref || github.ref_name != 'master'
steps:
- uses: actions/checkout@v3
- name: Checkout submodules
uses: ./.github/actions/automerge
with:
branch: ${{ env.BRANCH_NAME }}
repository: ${{ matrix.submodules }}
token: ${{ secrets.REST_TOKEN }}