forked from json-schema-org/website
-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (74 loc) · 3.25 KB
/
sync-contributors.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name : Sync Contributors Data
on:
schedule: # Run sunday at midnight every week
- cron: '0 0 * * 0'
workflow_dispatch:
jobs:
sync-contributors-data:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Get Token
uses: actions/create-github-app-token@v1
id: get_workflow_token
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}
- name: Fetch Contributors data
uses: actions/github-script@v7
env:
ORGS: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
with:
github-token: ${{ steps.get_workflow_token.outputs.token }}
script: |
const fs = require('fs');
let data = await github.paginate(github.rest.repos.listContributors, {
owner: process.env.ORGS,
repo: process.env.REPO,
per_page: 100,
headers: {
"X-GitHub-Api-Version": "2022-11-28",
},
});
// Filter the data to get only the required fields
data = data.map(({ login, id, avatar_url, html_url }) =>
({ login, id, avatar_url, html_url }));
// Store the data in a file
fs.writeFileSync('community.json', JSON.stringify(data, null, 2));
- name: Commit changes
run: |
git config user.name "the-json-schema-bot[bot]"
git config user.email "the-json-schema-bot[bot]@users.noreply.github.com"
git add community.json
git diff --quiet && git diff --staged --quiet || (git commit -m "chore(community): update community.json")
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v6
with:
token: ${{ steps.get_workflow_token.outputs.token }}
title: 'chore(community): update community.json'
body: 'This PR updates the community.json file with the latest contributors data.'
branch: 'update-contributors'
base: 'main'
author: 'the-json-schema-bot <the-json-schema-bot[bot]@users.noreply.github.com>'
branch-suffix: timestamp
labels: 'sync-contributors'
assignees: 'the-json-schema-bot'
draft: false
signoff: true
add-paths: 'community.json'
# Approving with github bot token because one cannot approve their own PRs
- name: Auto Approve
if: steps.cpr.outputs.pull-request-operation == 'created'
run: gh pr review --approve "${{ steps.cpr.outputs.pull-request-number }}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Auto Merge PR
if: steps.cpr.outputs.pull-request-operation == 'created'
uses: peter-evans/enable-pull-request-automerge@v3
with:
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
merge-method: 'squash'
token: ${{ steps.get_workflow_token.outputs.token }}