Skip to content

Instantly share code, notes, and snippets.

@tarao
Last active June 14, 2021 05:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tarao/cfce5ba342df61a0a89bf747b2f221fb to your computer and use it in GitHub Desktop.
Save tarao/cfce5ba342df61a0a89bf747b2f221fb to your computer and use it in GitHub Desktop.

OSS貢献を出力するワークフロー

  • issueを立てるとtarao/oss-contributionsを実行
    • issueタイトルにはfrom=YYYY-MM-DDto=YYYY-MM-DDを含むこと
    • issueのラベルにoss-contributionsをつけること
  • パラメータ
    • ORGANIZATION : ターゲットとなるOrganization
    • GITHUB_TOKEN : issueコメントをするためのトークン
    • OPEN_ACCESS_GITHUB_TOKEN : OSS貢献の情報を取得するためのトークン
      (内部情報引けないものが望ましい)
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: "[![](https://b.hatena.ne.jp/images/loading.gif) 計算中...](/${{ 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