diff options
| -rw-r--r-- | .github/workflows/pr-gh-actions.yml | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/.github/workflows/pr-gh-actions.yml b/.github/workflows/pr-gh-actions.yml new file mode 100644 index 00000000..fa0cd465 --- /dev/null +++ b/.github/workflows/pr-gh-actions.yml | |||
| @@ -0,0 +1,107 @@ | |||
| 1 | name: PR on GH Actions | ||
| 2 | |||
| 3 | on: | ||
| 4 | push: | ||
| 5 | tags: | ||
| 6 | - 'v*' | ||
| 7 | workflow_dispatch: | ||
| 8 | |||
| 9 | jobs: | ||
| 10 | |||
| 11 | SanitizeVersion: | ||
| 12 | runs-on: ubuntu-latest | ||
| 13 | |||
| 14 | outputs: | ||
| 15 | version: ${{ steps.version.outputs.version }} | ||
| 16 | |||
| 17 | steps: | ||
| 18 | - name: Extract version from the tag and set it as output | ||
| 19 | id: version | ||
| 20 | run: | | ||
| 21 | if [ "${{ github.ref_type }}" = "tag" ]; | ||
| 22 | then | ||
| 23 | version=$(echo "${{ github.ref_name }}" | sed -e "s/v//g" | grep -oP '^(\d+\.\d+\.\d+)$') | ||
| 24 | |||
| 25 | if [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; | ||
| 26 | then | ||
| 27 | echo "version=${version}" >> "$GITHUB_OUTPUT" | ||
| 28 | else | ||
| 29 | echo "version=none" >> "$GITHUB_OUTPUT" | ||
| 30 | fi | ||
| 31 | else | ||
| 32 | echo "version=none" >> "$GITHUB_OUTPUT" | ||
| 33 | fi | ||
| 34 | |||
| 35 | CreatePullRequest: | ||
| 36 | runs-on: ubuntu-latest | ||
| 37 | needs: | ||
| 38 | - SanitizeVersion | ||
| 39 | if: ${{ github.ref_type == 'tag' && needs.SanitizeVersion.outputs.version != 'none' }} | ||
| 40 | |||
| 41 | env: | ||
| 42 | TARGET_REPOSITORY: luarocks/gh-actions-luarocks | ||
| 43 | NEW_BRANCH: luarocks-${{ needs.SanitizeVersion.outputs.version }} | ||
| 44 | NEW_COMMIT_MSG: 'LuaRocks: update to ${{ needs.SanitizeVersion.outputs.version }}' | ||
| 45 | NEW_PR_TITLE: 'LuaRocks: update to ${{ needs.SanitizeVersion.outputs.version }}' | ||
| 46 | |||
| 47 | # comma (,) separated list | ||
| 48 | # of users to mention in the | ||
| 49 | # body of the Pull Request | ||
| 50 | USERS_TO_MENTION: hishamhm | ||
| 51 | |||
| 52 | steps: | ||
| 53 | |||
| 54 | - uses: actions/checkout@v4 | ||
| 55 | with: | ||
| 56 | repository: ${{ env.TARGET_REPOSITORY }} | ||
| 57 | token: ${{ secrets.GH_ACTIONS_LUAROCKS_TOKEN }} | ||
| 58 | path: gh-actions-luarocks | ||
| 59 | |||
| 60 | - name: Create a new branch | ||
| 61 | working-directory: gh-actions-luarocks | ||
| 62 | run: git checkout -b ${{ env.NEW_BRANCH }} | ||
| 63 | |||
| 64 | - name: Set user name and email on commit | ||
| 65 | working-directory: gh-actions-luarocks | ||
| 66 | run: | | ||
| 67 | git config user.name "github-actions[bot]" | ||
| 68 | git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
| 69 | |||
| 70 | - name: Replace default version on action.yml | ||
| 71 | working-directory: gh-actions-luarocks | ||
| 72 | run: | | ||
| 73 | sed -e "s/default: \".*\"/default: \"${{ needs.SanitizeVersion.outputs.version }}\"/g" -i action.yml | ||
| 74 | |||
| 75 | - name: Stage changes | ||
| 76 | working-directory: gh-actions-luarocks | ||
| 77 | run: git add action.yml | ||
| 78 | |||
| 79 | - name: Commit changes | ||
| 80 | working-directory: gh-actions-luarocks | ||
| 81 | run: git commit "--message=${{ env.NEW_COMMIT_MSG }}" | ||
| 82 | |||
| 83 | - name: Print diff | ||
| 84 | working-directory: gh-actions-luarocks | ||
| 85 | run: git show | ||
| 86 | |||
| 87 | - name: Push changes | ||
| 88 | working-directory: gh-actions-luarocks | ||
| 89 | run: git push --set-upstream origin ${{ env.NEW_BRANCH }} | ||
| 90 | |||
| 91 | - name: Submit Pull Request | ||
| 92 | working-directory: gh-actions-luarocks | ||
| 93 | env: | ||
| 94 | GITHUB_TOKEN: ${{ secrets.GH_ACTIONS_LUAROCKS_TOKEN }} | ||
| 95 | run: | | ||
| 96 | PR_BODY="" | ||
| 97 | |||
| 98 | IFS=',' read -ra reviewers <<< "${{ env.USERS_TO_MENTION }}" | ||
| 99 | for i in "${reviewers[@]}"; do | ||
| 100 | PR_BODY+="CC @${i} " | ||
| 101 | done | ||
| 102 | |||
| 103 | gh pr create \ | ||
| 104 | --repo "${{ env.TARGET_REPOSITORY }}" \ | ||
| 105 | --head ${{ env.NEW_BRANCH }} \ | ||
| 106 | --title "${{ env.NEW_PR_TITLE }}" \ | ||
| 107 | --body "${PR_BODY}" \ No newline at end of file | ||
