- issueを立てるとtarao/oss-contributionsを実行
- issueタイトルには
from=YYYY-MM-DD
とto=YYYY-MM-DD
を含むこと - issueのラベルに
oss-contributions
をつけること
- issueタイトルには
- パラメータ
ORGANIZATION
: ターゲットとなるOrganizationGITHUB_TOKEN
: issueコメントをするためのトークンOPEN_ACCESS_GITHUB_TOKEN
: OSS貢献の情報を取得するためのトークン
(内部情報引けないものが望ましい)
Last active
June 14, 2021 05:33
-
-
Save tarao/cfce5ba342df61a0a89bf747b2f221fb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: OSS contributions | |
on: | |
issues: | |
types: [labeled] | |
jobs: | |
preconditions: | |
name: Check preconditions | |
if: contains(github.event.label.name, 'oss-contributions') | |
runs-on: ubuntu-latest | |
outputs: | |
from: ${{ steps.parameter.outputs.from }} | |
to: ${{ steps.parameter.outputs.to }} | |
check: ${{ steps.check.outputs.check }} | |
steps: | |
- id: parameter | |
name: Extract parameter from issue title | |
run: | | |
echo '${{ github.event.issue.title }}' | perl -MList::Util -ne 'List::Util::pairmap { print "::set-output name=${a}::${b}\n" } ($_ =~ m!\b(from|to)\s*=\s*([0-9]{4}-[0-9]{2}-[0-9]{2})\b!g)' | |
- id: check | |
name: Check the parameter | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
COMMENTS_URL: ${{ github.event.issue.comments_url }} | |
MESSAGE: "パラメータが足りません: `from=YYYY-MM-DD`と`to=YYYY-MM-DD`をissueのタイトルに指定してください" | |
run: | | |
if [ -n '${{ steps.parameter.outputs.from }}' ] && [ -n '${{ steps.parameter.outputs.to }}' ]; then | |
echo "::set-output name=check::ok" | |
else | |
curl -s -X POST \ | |
-H "Authorization: token ${GITHUB_TOKEN}" \ | |
-d "$(jq -n --arg body "$MESSAGE" '{"body":$body}')" \ | |
${COMMENTS_URL} | jq -r '"::set-output name=id::" + (.id|tostring)' | |
fi | |
aggregate_oss_contributions: | |
name: Aggregate OSS contributions | |
needs: preconditions | |
if: contains(needs.preconditions.outputs.check, 'ok') | |
runs-on: ubuntu-latest | |
steps: | |
- name: Comment on the issue | |
id: comment | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
COMMENTS_URL: ${{ github.event.issue.comments_url }} | |
MESSAGE: "[ 計算中...](/${{ github.repository }}/actions/runs/${{ github.run_id }})" | |
run: | | |
curl -s -X POST \ | |
-H "Authorization: token ${GITHUB_TOKEN}" \ | |
-d "$(jq -n --arg body "$MESSAGE" '{"body":$body}')" \ | |
${COMMENTS_URL} | jq -r '"::set-output name=id::" + (.id|tostring)' | |
- name: Checkout tarao/oss-contributions | |
uses: actions/checkout@v2 | |
with: | |
repository: tarao/oss-contributions | |
- name: Setup Ruby | |
uses: ruby/setup-ruby@v1 | |
with: | |
ruby-version: 2.7 | |
bundler-cache: true | |
- name: Bundle install | |
run: bundle install | |
- name: Aggregate OSS contributions | |
env: | |
GITHUB_TOKEN: ${{ secrets.OPEN_ACCESS_GITHUB_TOKEN }} | |
run: | | |
bundle exec ruby oss_contributions.rb \ | |
-o ${{ secrets.ORGANIZATION }} \ | |
--sort=stargazers \ | |
--from=${{ needs.preconditions.outputs.from }} \ | |
--to=${{ needs.preconditions.outputs.to }} \ | |
--render=templates/users.md.erb \ | |
> contributed_users.md | |
- name: Output the result | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
REPOSITORY_URL: ${{ github.event.issue.repository_url }} | |
run: | | |
jq -n --rawfile body contributed_users.md '{"body":$body}' > message.json | |
curl -s -X PATCH \ | |
-H "Authorization: token ${GITHUB_TOKEN}" \ | |
-d @message.json \ | |
${REPOSITORY_URL}/issues/comments/${{ steps.comment.outputs.id }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment