forked from json-schema-org/website
-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (122 loc) · 5.07 KB
/
sync-project-roadmap.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name : Sync Project Roadmap Data
on:
schedule: # Run sundat at 00:05 every week
- cron: '5 0 * * 0'
workflow_dispatch:
jobs:
sync-roadmap-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 }}
# fetch project data and store it in a file
- name: Fetch project data
env:
GH_TOKEN: ${{ steps.get_workflow_token.outputs.token }} # GitHub App token stored in secrets
PROJECT_ID: ${{vars.ROADMAP_PROJECT_ID}} # Project ID
run: |
gh api graphql -f query='
query($PROJECT_ID : ID!) {
node(id: $PROJECT_ID) {
... on ProjectV2 {
items(first: 20) {
nodes {
id
fieldValues(first: 8) {
nodes {
... on ProjectV2ItemFieldTextValue {
text
field {
... on ProjectV2FieldCommon {
name
}
}
}
... on ProjectV2ItemFieldDateValue {
date
field {
... on ProjectV2FieldCommon {
name
}
}
}
... on ProjectV2ItemFieldSingleSelectValue {
name
field {
... on ProjectV2FieldCommon {
name
}
}
}
}
}
content {
... on DraftIssue {
title
body
}
... on Issue {
title
assignees(first: 10) {
nodes {
login
}
}
}
... on PullRequest {
title
assignees(first: 10) {
nodes {
login
}
}
}
}
}
}
}
}
}' -f PROJECT_ID=$PROJECT_ID | jq '.data.node.items.nodes' > project_data.json
# commit updated project data
- 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 project_data.json
git diff --quiet && git diff --staged --quiet || (git commit -m "chore(project_data): update project_data.json")
# create a pull request
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v6
with:
token: ${{ steps.get_workflow_token.outputs.token }}
title: 'chore(project_data): update project_data.json'
body: 'This PR updates the project_data.json file with the latest project data.'
branch: 'update-project-data'
base: 'main'
author: 'the-json-schema-bot <the-json-schema-bot[bot]@users.noreply.github.com>'
branch-suffix: timestamp
labels: 'sync-project-data'
assignees: 'the-json-schema-bot'
draft: false
signoff: true
add-paths: 'project_data.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 }}