|
| 1 | +--- |
| 2 | + |
| 3 | +name: Mirror to Gitlab to trigger CI |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + pull_request_target: |
| 8 | + schedule: |
| 9 | + - cron: '1 5 2 * *' |
| 10 | + |
| 11 | +jobs: |
| 12 | + check_permission: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + if: >- |
| 15 | + (github.repository_owner == 'Parallel-in-Time') && |
| 16 | + ((github.event_name == 'push') || |
| 17 | + (github.event_name == 'schedule') || |
| 18 | + ((github.event_name == 'pull_request_target') && |
| 19 | + (contains(github.event.pull_request.labels.*.name, 'gitlab-mirror')) |
| 20 | + ) |
| 21 | + ) |
| 22 | + steps: |
| 23 | + - name: Query permissions of triggering actor |
| 24 | + id: query_permission_triggering_actor |
| 25 | + if: github.event_name == 'pull_request_target' |
| 26 | + uses: actions-cool/check-user-permission@v2 |
| 27 | + with: |
| 28 | + username: ${{ github.triggering_actor }} |
| 29 | + require: 'write' |
| 30 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 31 | + - name: Interpret the queried result |
| 32 | + if: github.event_name == 'pull_request_target' |
| 33 | + run: | |
| 34 | + echo "Current permission level is ${{ steps.query_permission_triggering_actor.outputs.user-permission }}" |
| 35 | + echo "Job originally triggered by ${{ github.actor }}" |
| 36 | + echo "Checking permission returned ${{ steps.query_permission_triggering_actor.outputs.require-result }}" |
| 37 | + if ${{ steps.query_permission_triggering_actor.outputs.require-result }} |
| 38 | + then |
| 39 | + echo 'Permissions granted' |
| 40 | + exit 0 |
| 41 | + else |
| 42 | + echo 'Not enough permissions. Please ask a member of Parallel-in-Time to rerun the job.' |
| 43 | + exit 1 |
| 44 | + fi |
| 45 | + - name: Pass if workflow from push or schedule |
| 46 | + if: >- |
| 47 | + (github.event_name == 'push') || |
| 48 | + (github.event_name == 'schedule') |
| 49 | + run: exit 0 |
| 50 | + # - name: Fail for other triggers |
| 51 | + # if: >- |
| 52 | + # (github.event_name != 'push') && |
| 53 | + # (github.event_name != 'schedule') && |
| 54 | + # (github.event_name != 'pull_request_target') |
| 55 | + # run: exit 1 |
| 56 | + |
| 57 | + mirror_to_gitlab: |
| 58 | + runs-on: ubuntu-latest |
| 59 | + if: >- |
| 60 | + (github.repository_owner == 'Parallel-in-Time') && |
| 61 | + ((github.event_name == 'push') || |
| 62 | + (github.event_name == 'schedule') || |
| 63 | + ((github.event_name == 'pull_request_target') && |
| 64 | + (contains(github.event.pull_request.labels.*.name, 'gitlab-mirror')) |
| 65 | + ) |
| 66 | + ) |
| 67 | + needs: |
| 68 | + - check_permission |
| 69 | + steps: |
| 70 | + - name: set proper sha |
| 71 | + run: | |
| 72 | + echo "${{ github.event_name }}" |
| 73 | + if [ "${{ github.event_name }}" == 'push' ] || [ "${{ github.event_name }}" == 'schedule' ] |
| 74 | + then |
| 75 | + echo "USED_SHA=${{ github.sha }}" >> "$GITHUB_ENV" |
| 76 | + fi |
| 77 | + if [ "${{ github.event_name }}" == 'pull_request_target' ] |
| 78 | + then |
| 79 | + echo "USED_SHA=${{ github.event.pull_request.head.sha }}" >> "$GITHUB_ENV" |
| 80 | + fi |
| 81 | + - name: Checkout |
| 82 | + uses: actions/checkout@v4 |
| 83 | + with: |
| 84 | + ref: "${{ env.USED_SHA }}" |
| 85 | + persist-credentials: false |
| 86 | + - name: check if merge is possible (merge is used for testing) |
| 87 | + if: github.event_name == 'pull_request_target' |
| 88 | + run: | |
| 89 | + if $(git rev-parse --is-shallow-repository); then |
| 90 | + git fetch --unshallow |
| 91 | + else |
| 92 | + git fetch |
| 93 | + fi |
| 94 | + echo "Checkout of ${{ github.base_ref }}" |
| 95 | + git checkout "${{ github.base_ref }}" |
| 96 | + echo "Git pull" |
| 97 | + git pull |
| 98 | + MIRROR_BRANCH="TEMPORARY_MERGE_PR_${{ github.event.number }}" |
| 99 | + echo MIRROR_BRANCH="$MIRROR_BRANCH" >> $GITHUB_ENV |
| 100 | + echo "Create new branch $MIRROR_BRANCH and check it out" |
| 101 | + git checkout -b "$MIRROR_BRANCH" |
| 102 | + echo "Setting git committer info, so that merge-commit can be created" |
| 103 | + git config user.email "[email protected]" |
| 104 | + git config user.name "Sync bot" |
| 105 | + echo "Merge the two parts of the Merge-Request to test the resulting version" |
| 106 | + git merge "${{ github.event.pull_request.head.sha }}" |
| 107 | + - name: Mirror and wait for Gitlab-CI |
| 108 | + uses: jakob-fritz/[email protected] |
| 109 | + env: |
| 110 | + MODE: 'all' # Either 'mirror', 'get_status', 'get_artifact', or 'all' |
| 111 | + GITLAB_TOKEN: ${{ secrets.GITLAB_SECRET }} |
| 112 | + FORCE_PUSH: "true" |
| 113 | + GITLAB_HOSTNAME: "gitlab.jsc.fz-juelich.de" |
| 114 | + GITLAB_PROJECT_ID: "6029" |
| 115 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 116 | + MIRROR_BRANCH: ${{ env.MIRROR_BRANCH }} |
0 commit comments