-
Notifications
You must be signed in to change notification settings - Fork 1
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
New GitHub workflow to auto-update list of contributors #6
Conversation
5039c39
to
b6bcf89
Compare
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' }} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed anymore!
- 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" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All removed!
b6bcf89
to
2feab9d
Compare
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' \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filter on author added.
# 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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All removed!
6d7ff58
to
df983a3
Compare
12a6c3d
to
d85220d
Compare
Thanks to the new version `akhilmhdh/[email protected]`.
d85220d
to
fb09116
Compare
98ba0e6
to
2ef95ff
Compare
23b9969
to
999b062
Compare
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
56d2a3e
to
365bbe2
Compare
New GitHub workflow to auto-update the list of contributors (#6)
When this workflow runs it does:
Update the list of contributors
If there was already a previous PR
This is not executed if the update was made through a commit
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
GitHub CLI
gh
is preinstalled on all GitHub-hosted runnershttps://docs.github.com/en/actions/advanced-guides/using-github-cli-in-workflows
See all included tools for each runner operating system:
https://github.com/actions/virtual-environments/tree/main/images
For instance, the runner Ubuntu 20.04.3 LTS.
GitHub REST API
https://docs.github.com/en/rest
GitHub CLI manual
https://cli.github.com/manual