From b45502ab0f1b7e1a02313036f115c213c8ee0ef9 Mon Sep 17 00:00:00 2001 From: Luau Project Date: Mon, 30 Jun 2025 12:17:42 -0300 Subject: ci: automate PR to update LuaRocks version on gh-actions-luarocks (#1808) On every tagged release of LuaRocks, there is the need to update LuaRocks version at [https://github.com/luarocks/gh-actions-luarocks/blob/22fa5618dc4ddff1fb251b3b38a0766a8c9ae47f/action.yml#L13](https://github.com/luarocks/gh-actions-luarocks/blob/22fa5618dc4ddff1fb251b3b38a0766a8c9ae47f/action.yml#L13) in the repository [https://github.com/luarocks/gh-actions-luarocks](https://github.com/luarocks/gh-actions-luarocks). Often forgotten, the default LuaRocks version on `gh-actions-luarocks` may lag behind the latest LuaRocks release. Motivated by this comment [https://github.com/luarocks/gh-actions-luarocks/pull/7#issuecomment-2997223378](https://github.com/luarocks/gh-actions-luarocks/pull/7#issuecomment-2997223378), to address this problem, incorporating the changes on this pull request, a new workflow was created to proceed in the following manner: 1. Once a tag is pushed (in the usual format `vX.Y.Z`) on [https://github.com/luarocks/luarocks](https://github.com/luarocks/luarocks), or in a manual workflow triggered by the tag ref, a sanitization step is performed to extract `X.Y.Z` from the `vX.Y.Z` in the job `SanitizeVersion`; 2. In a subsequent job (`CreatePullRequest`), a PR is created at [https://github.com/luarocks/gh-actions-luarocks](https://github.com/luarocks/gh-actions-luarocks) replacing the outdated version by the value `X.Y.Z` extracted earlier. --- .github/workflows/pr-gh-actions.yml | 107 ++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 .github/workflows/pr-gh-actions.yml 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 @@ +name: PR on GH Actions + +on: + push: + tags: + - 'v*' + workflow_dispatch: + +jobs: + + SanitizeVersion: + runs-on: ubuntu-latest + + outputs: + version: ${{ steps.version.outputs.version }} + + steps: + - name: Extract version from the tag and set it as output + id: version + run: | + if [ "${{ github.ref_type }}" = "tag" ]; + then + version=$(echo "${{ github.ref_name }}" | sed -e "s/v//g" | grep -oP '^(\d+\.\d+\.\d+)$') + + if [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; + then + echo "version=${version}" >> "$GITHUB_OUTPUT" + else + echo "version=none" >> "$GITHUB_OUTPUT" + fi + else + echo "version=none" >> "$GITHUB_OUTPUT" + fi + + CreatePullRequest: + runs-on: ubuntu-latest + needs: + - SanitizeVersion + if: ${{ github.ref_type == 'tag' && needs.SanitizeVersion.outputs.version != 'none' }} + + env: + TARGET_REPOSITORY: luarocks/gh-actions-luarocks + NEW_BRANCH: luarocks-${{ needs.SanitizeVersion.outputs.version }} + NEW_COMMIT_MSG: 'LuaRocks: update to ${{ needs.SanitizeVersion.outputs.version }}' + NEW_PR_TITLE: 'LuaRocks: update to ${{ needs.SanitizeVersion.outputs.version }}' + + # comma (,) separated list + # of users to mention in the + # body of the Pull Request + USERS_TO_MENTION: hishamhm + + steps: + + - uses: actions/checkout@v4 + with: + repository: ${{ env.TARGET_REPOSITORY }} + token: ${{ secrets.GH_ACTIONS_LUAROCKS_TOKEN }} + path: gh-actions-luarocks + + - name: Create a new branch + working-directory: gh-actions-luarocks + run: git checkout -b ${{ env.NEW_BRANCH }} + + - name: Set user name and email on commit + working-directory: gh-actions-luarocks + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + + - name: Replace default version on action.yml + working-directory: gh-actions-luarocks + run: | + sed -e "s/default: \".*\"/default: \"${{ needs.SanitizeVersion.outputs.version }}\"/g" -i action.yml + + - name: Stage changes + working-directory: gh-actions-luarocks + run: git add action.yml + + - name: Commit changes + working-directory: gh-actions-luarocks + run: git commit "--message=${{ env.NEW_COMMIT_MSG }}" + + - name: Print diff + working-directory: gh-actions-luarocks + run: git show + + - name: Push changes + working-directory: gh-actions-luarocks + run: git push --set-upstream origin ${{ env.NEW_BRANCH }} + + - name: Submit Pull Request + working-directory: gh-actions-luarocks + env: + GITHUB_TOKEN: ${{ secrets.GH_ACTIONS_LUAROCKS_TOKEN }} + run: | + PR_BODY="" + + IFS=',' read -ra reviewers <<< "${{ env.USERS_TO_MENTION }}" + for i in "${reviewers[@]}"; do + PR_BODY+="CC @${i} " + done + + gh pr create \ + --repo "${{ env.TARGET_REPOSITORY }}" \ + --head ${{ env.NEW_BRANCH }} \ + --title "${{ env.NEW_PR_TITLE }}" \ + --body "${PR_BODY}" \ No newline at end of file -- cgit v1.2.3-55-g6feb