-
Notifications
You must be signed in to change notification settings - Fork 1
162 lines (149 loc) · 5.06 KB
/
banner.yaml
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
#name: Update banner
#
#on:
# issues:
# types:
# - opened
# - edited
# - reopened
# - labeled
#
#jobs:
# update_files:
# runs-on: ubuntu-latest
#
# permissions:
# contents: write
# pull-requests: write
#
# name: Convert New Issue to GHG Dashboard Dynamic Data
# if: contains(github.event.issue.labels.*.name, 'banner')
# steps:
# - name: Checkout
# uses: actions/checkout@v3
#
# - name: GitHub Issue to JSON
# uses: actions/github-script@v6
# with:
# script: |
# const fs = require('fs');
# const issue = context.payload.issue;
# const jsonContent = JSON.stringify(issue, null, 2);
# if (!fs.existsSync('_data')){
# fs.mkdirSync('_data');
# }
# fs.writeFileSync('_data/issue.json', jsonContent);
# console.log('Issue converted to JSON and written to _data/issue.json');
# console.log('Content:', jsonContent);
#
# - name: List _data directory
# run: ls -l _data
#
# - name: Update the existing files
# run: python scripts/banner.py
#
# - name: Configure Git
# run: |
# git config --local user.email "[email protected]"
# git config --local user.name "GitHub Action"
#
# - name: Checkout or Create Staging Branch
# run: |
# git fetch
# if git show-ref --verify --quiet refs/remotes/origin/staging; then
# git branch -D staging
# git push origin --delete staging
# fi
# git checkout -b staging
# git push --set-upstream origin staging
#
#
# - name: Commit files
# id: commit-changes
# run: |
# git add banner.json
# git diff-index --quiet HEAD || echo "changes_detected=true" >> $GITHUB_ENV
# git commit -m "Updating banner for #${{ github.event.issue.number }}" || echo "No changes to commit"
#
# - name: Push changes
# if: env.changes_detected == 'true'
# run: |
# git pull --rebase --strategy-option=theirs origin staging
# git push --set-upstream origin staging
#
# - name: Create pull request to main
# if: env.changes_detected == 'true'
# run: |
# echo -e "Scheduled banner update ${{ github.event.issue.number }}. 🔔 @slesaad\nAutomatically created by Github action" > msg
# gh pr create -H staging -B main --title 'Update banner for #${{ github.event.issue.number }}' --body-file msg --reviewer slesaad
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
#
name: Update banner
on:
issues:
types:
- opened
- edited
- reopened
- labeled
jobs:
update_files:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
name: Convert New Issue to GHG Dashboard Dynamic Data
if: contains(github.event.issue.labels.*.name, 'banner')
steps:
- name: Checkout
uses: actions/checkout@v3
- name: GitHub Issue to JSON
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const issue = context.payload.issue;
const jsonContent = JSON.stringify(issue, null, 2);
if (!fs.existsSync('_data')){
fs.mkdirSync('_data');
}
fs.writeFileSync('_data/issue.json', jsonContent);
console.log('Issue converted to JSON and written to _data/issue.json');
console.log('Content:', jsonContent);
- name: List _data directory
run: ls -l _data
- name: Update the existing files
run: python scripts/banner.py
- name: Configure Git
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
- name: Checkout or Create Staging Branch
run: |
git fetch
if git show-ref --verify --quiet refs/remotes/origin/staging; then
git checkout staging
git reset --hard origin/staging
else
git checkout -b staging
git push --set-upstream origin staging
fi
- name: Commit files
id: commit-changes
run: |
git add banner.json
git diff-index --quiet HEAD || echo "changes_detected=true" >> $GITHUB_ENV
git commit -m "Updating banner for #${{ github.event.issue.number }}" || echo "No changes to commit"
- name: Push changes
if: env.changes_detected == 'true'
run: |
git pull --rebase --strategy-option=theirs origin staging
git push --set-upstream origin staging
- name: Create pull request to main
if: env.changes_detected == 'true'
run: |
echo -e "Scheduled banner update ${{ github.event.issue.number }}. 🔔 @slesaad\nAutomatically created by Github action" > msg
gh pr create -H staging -B main --title 'Update banner for #${{ github.event.issue.number }}' --body-file msg --reviewer slesaad
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}