forked from salesagility/SuiteCRM
-
Notifications
You must be signed in to change notification settings - Fork 2
190 lines (189 loc) · 8.25 KB
/
Projects_MoveToRelease.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
name: Projects Move to release
on:
release:
types: [published]
jobs:
move_to_release_project:
name: Move to release project
runs-on: ubuntu-latest
steps:
- name: Set env
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Get project Updates data
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
ORGANIZATION: SinergiaTIC
PROJECT_NUMBER: 2
run: |
gh api graphql -f query='
query($org: String!, $number: Int!) {
organization(login: $org){
projectV2(number: $number) {
id
fields(first:20) {
nodes {
... on ProjectV2Field {
id
name
}
... on ProjectV2SingleSelectField {
id
name
options {
id
name
}
}
}
}
items(first:100) {
nodes {
... on ProjectV2Item {
id
fieldValues(first:100) {
nodes {
... on ProjectV2ItemFieldSingleSelectValue {
name
item {
id
content{
... on PullRequest{
id
}
}
}
}
}
}
}
}
}
}
}
}' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json
echo 'PROJECT_ID='$(jq '.data.organization.projectV2.id' project_data.json) >> $GITHUB_ENV
echo 'STATUS_FIELD_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .id' project_data.json) >> $GITHUB_ENV
echo 'STATUS_VALUE='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name=="Ready for next release") |.id' project_data.json) >> $GITHUB_ENV
PROJECT_ITEMS=$(jq '.data.organization.projectV2.items' project_data.json)
echo 'FILTERED_ITEMS='$(echo $PROJECT_ITEMS | jq -r '.nodes[] | .fieldValues.nodes[] | select(.name=="Ready for next release") | .') >> $GITHUB_ENV
- name: Get project Release data
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
ORGANIZATION: SinergiaTIC
PROJECT_RELEASE: 5
run: |
gh api graphql -f query='
query($org: String!, $number: Int!) {
organization(login: $org){
projectV2(number: $number) {
id
fields(first:20) {
nodes {
... on ProjectV2Field {
id
name
}
... on ProjectV2SingleSelectField {
id
name
options {
id
name
}
}
}
}
}
}
}' -f org=$ORGANIZATION -F number=$PROJECT_RELEASE > project_data.json
echo 'PROJECT_ID_RELEASE='$(jq '.data.organization.projectV2.id' project_data.json) >> $GITHUB_ENV
echo 'VERSION_FIELD_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Version") | .id' project_data.json) >> $GITHUB_ENV
echo 'DATE_FIELD_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Date") | .id' project_data.json) >> $GITHUB_ENV
echo 'CURRENT_DATE='$(date +'%Y-%m-%d') >> $GITHUB_ENV
- name: Add PRs to release and add version
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
VERSION_NUMBER: ${{ env.RELEASE_VERSION }}
run: |
FILTERED_ITEMS_CONTENT_ID=$(echo $FILTERED_ITEMS | jq -r '.item.content.id')
for PR_ITEM_CONTENT_ID in $FILTERED_ITEMS_CONTENT_ID; do
ITEM_ID="$( gh api graphql -f query='
mutation($project:ID!, $pr:ID!) {
addProjectV2ItemById(input: {projectId: $project, contentId: $pr}) {
item {
id
}
}
}' -f project=$PROJECT_ID_RELEASE -f pr=$PR_ITEM_CONTENT_ID --jq '.data.addProjectV2ItemById.item.id')"
echo $ITEM_ID
gh api graphql -f query='
mutation (
$project: ID!
$item: ID!
$version_field: ID!
$version_value: String!
) {
set_version: updateProjectV2ItemFieldValue(input: {
projectId: $project
itemId: $item
fieldId: $version_field
value: {
text: $version_value
}
}) {
projectV2Item {
id
}
}
}' -f project=$PROJECT_ID_RELEASE -f item=$ITEM_ID -f version_field=$VERSION_FIELD_ID -f version_value=$VERSION_NUMBER --silent
gh api graphql -f query='
mutation (
$project: ID!
$item: ID!
$date_field: ID!
$date_value: Date!
) {
set_date: updateProjectV2ItemFieldValue(input: {
projectId: $project
itemId: $item
fieldId: $date_field
value: {
date: $date_value
}
})
{
projectV2Item {
id
}
}
}' -f project=$PROJECT_ID_RELEASE -f item=$ITEM_ID -f date_field=$DATE_FIELD_ID -f date_value=$CURRENT_DATE --silent
done
- name: Remove PRs from updates
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
FILTERED_ITEMS_ITEM_ID=$(echo $FILTERED_ITEMS | jq -r '.item.id')
for PR_ITEM_ID in $FILTERED_ITEMS_ITEM_ID; do
gh api graphql -f query='
mutation (
$project: ID!
$item: ID!
) {
delete_item: deleteProjectV2Item(input: {
projectId: $project
itemId: $item
}) {
deletedItemId
}
}' -f project=$PROJECT_ID -f item=$PR_ITEM_ID -f status_field=$STATUS_FIELD_ID --silent
done
# - name: Add PR Number as Tag
# uses: actions/github-script@v6
# with:
# script: |
# github.rest.git.createRef({
# owner: context.repo.owner,
# repo: context.repo.repo,
# ref: 'refs/tags/v${{ github.event.pull_request.number }}',
# sha: context.sha
# })