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 GitHub workflow to auto-update list of contributors #6

Merged
merged 7 commits into from
Nov 9, 2021

Conversation

MrChocolatine
Copy link
Contributor

@MrChocolatine MrChocolatine commented Nov 5, 2021

New GitHub workflow to auto-update the list of contributors (#6)

When this workflow runs it does:

  1. Update the list of contributors

    • By directly pushing a commit on the default branch
    • Or, if the default branch is protected, by creating a pull request
  2. If there was already a previous PR
    This is not executed if the update was made through a commit

    1. A link to the new PR is posted on the previous PR
    2. And the previous PR is closed

For more details, checkout https://github.com/akhilmhdh/contributors-readme-action .

Input that can be passed from the caller workflow:

  • use_username (optional)
    If contributors should be listed with their username instead of their full name.

Currently implemented in the repositories


Notes

@MrChocolatine MrChocolatine force-pushed the add-workflow-auto-update-list-contributors branch 4 times, most recently from 5039c39 to b6bcf89 Compare November 5, 2021 15:51
with:
commit_message: 'chore: auto-update contributors list (GH Action)'
committer_username: 'akhilmhdh/contributors-readme-action'
is_protected: ${{ steps.default_branch.outputs.is_protected == 'true' }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing is_protected might not be needed in the future:
akhilmhdh/contributors-readme-action#37

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed anymore!

Comment on lines 15 to 31
- name: Check if the default branch is protected
id: default_branch
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
defaultBranch="$( gh api /repos/${{ github.repository }} \
--method GET \
--jq '.default_branch'
)"

isProtected="$( \
gh api /repos/${{ github.repository }}/branches/$defaultBranch \
--jq '.protected'
)"

echo "::set-output name=is_protected::$isProtected"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block might not be needed in the future:
akhilmhdh/contributors-readme-action#37

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All removed!

@MrChocolatine MrChocolatine force-pushed the add-workflow-auto-update-list-contributors branch from b6bcf89 to 2feab9d Compare November 5, 2021 16:58
Comment on lines 40 to 43
gh api search/issues \
--method GET \
--raw-field q='repo:${{ github.repository }} type:pr state:open "Auto-update list of contributors" in:title' \
--jq '.items.[0].number' \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the filter query:

q='repo:${{ github.repository }} type:pr state:open "Auto-update list of contributors" in:title'

It is easy to try to build such a query via GitHub, and values do not need to be escaped, for instance:
https://github.com/pulls?q=repo:peopledoc/ember-cli-embedded%20type:pr%20state:closed%20%22release%22%20in:title

Plus, I could not find a better query to ensure to get the right pull request. Filtering on the title seems to be the most reliable way 🤔 . I could eventually add a filter on the author app/github-actions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filter on author added.

Comment on lines 69 to 90
# The Action `akhilmhdh/contributors-readme-action` creates PRs with a fixed title:
# https://github.com/akhilmhdh/contributors-readme-action/blob/v2.3/src/index.js#L169
- name: Rename the new PR with a better title
if: ${{ steps.default_branch.outputs.is_protected == 'true' }}
id: rename_new_pr
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
sleep 10 # Some delay is needed to make sure GitHub had time to create the new PR

ID_PR="$( \
gh api search/issues \
--method GET \
--raw-field q='repo:${{ github.repository }} type:pr state:open "contributors readme action update" in:title' \
--jq '.items.[0].number' \
)"

gh pr edit $ID_PR \
--repo ${{ github.repository }} \
--title "Auto-update list of contributors"

echo "::set-output name=id_new_pr::$ID_PR"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole step may not be needed in the future:
akhilmhdh/contributors-readme-action#35

Instead we will be able to do pass an input to the step responsible for creating the PR:

      - uses: akhilmhdh/[email protected]
        with:
          pr_title: My Custom Title

Plus, the GitHub Action akhilmhdh/contributors-readme-action may be able to output the ID of the PR that was created.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All removed!

@MrChocolatine MrChocolatine force-pushed the add-workflow-auto-update-list-contributors branch 19 times, most recently from 6d7ff58 to df983a3 Compare November 8, 2021 17:31
@MrChocolatine MrChocolatine force-pushed the add-workflow-auto-update-list-contributors branch 8 times, most recently from 12a6c3d to d85220d Compare November 8, 2021 22:13
@MrChocolatine MrChocolatine force-pushed the add-workflow-auto-update-list-contributors branch from d85220d to fb09116 Compare November 8, 2021 22:15
@MrChocolatine MrChocolatine changed the title add workflow auto update list contributors New GitHub workflow to auto-update list of contributors Nov 9, 2021
@MrChocolatine MrChocolatine marked this pull request as ready for review November 9, 2021 08:57
@MrChocolatine MrChocolatine force-pushed the add-workflow-auto-update-list-contributors branch from 98ba0e6 to 2ef95ff Compare November 9, 2021 09:20
@MrChocolatine MrChocolatine force-pushed the add-workflow-auto-update-list-contributors branch from 23b9969 to 999b062 Compare November 9, 2021 09:33
Mentioning `readme` in the filename does not really make since we can
make the GitHub Action updates another file, see:

https://github.com/akhilmhdh/contributors-readme-action/blob/v2.3.2/.github/workflows/main.yml#L16-L17
@MrChocolatine MrChocolatine merged commit 51b71a1 into main Nov 9, 2021
@MrChocolatine MrChocolatine deleted the add-workflow-auto-update-list-contributors branch November 9, 2021 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants