-
Notifications
You must be signed in to change notification settings - Fork 1
219 lines (218 loc) · 9.33 KB
/
news-post-lpb.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
name: Post news to Lighthouse Platform Backend (LPB)
on:
pull_request:
types:
- opened
- synchronize
- reopened
- closed
branches: [main]
paths:
- "content/website/**"
jobs:
gather_content:
name: Gather the changed content
runs-on: ubuntu-latest
outputs:
rename_warning: ${{ steps.get_target_environment.outputs.rename_warning }}
target_environment: ${{ steps.get_target_environment.outputs.target_environment }}
steps:
- id: get_target_environment
name: Determine Target Environment
run: |
TARGET_ENVIRONMENT="development"
if [ "${{ github.event.pull_request.merged }}" == "true" ]; then
TARGET_ENVIRONMENT="production"
fi
echo $TARGET_ENVIRONMENT
echo "target_environment=$TARGET_ENVIRONMENT" >> $GITHUB_OUTPUT
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- id: pr_files
uses: Ana06/[email protected]
with:
filter: "content/website/**"
- id: upload_content
name: Find files and send them
continue-on-error: true
run: |
# If it's a PR change from a space delimited list to one file per line
if [ "${{ steps.pr_files.outputs.added_modified_renamed }}" != "" ]; then
touch changed-files.txt
for f in `echo "${{ steps.pr_files.outputs.added_modified_renamed }}"`; do
echo $f >> changed-files.txt
done
fi
if [ "${{ steps.pr_files.outputs.renamed }}" != "" ]; then
echo "rename_warning=TRUE" >> $GITHUB_OUTPUT
fi
echo "Expected files changes:"
cat changed-files.txt
- name: Save changed files list
uses: actions/upload-artifact@v1
with:
name: changed-files
path: changed-files.txt
send_content_to_development:
name: Send content to development LPB
needs: [gather_content]
environment:
name: development
url: https://dev-developer.va.gov
runs-on: ubuntu-latest
if: needs.gather_content.outputs.target_environment == 'development'
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: NPM install
run: npm ci
- id: get_bearer_token
name: Get Bearer Token
env:
LPB_HOST: "dev-api.va.gov"
LPB_CLIENT_ID: ${{ secrets.LPB_CLIENT_ID }}
LPB_RSA_TOKEN: ${{ secrets.LPB_RSA_SECRET }}
OKTA_TOKEN_AUD: "https://deptva-eval.okta.com/oauth2/ausg95zxf6dFPccy02p7/v1/token"
run: echo "$LPB_RSA_TOKEN" > ./rsa.pem;
ls -la;
wc -l ./rsa.pem;
node ./get-bearer-token.js $LPB_CLIENT_ID ./rsa.pem $LPB_HOST $OKTA_TOKEN_AUD;
BEARER_TOKEN=`cat ./bearer.token`;
echo "bearer_token=$BEARER_TOKEN" >> $GITHUB_ENV;
- name: Get file list
uses: actions/download-artifact@v1
with:
name: changed-files
- name: Send content to development
env:
LPB_HOST: "dev-api.va.gov"
run:
for n in `cat changed-files/changed-files.txt | grep 'content/website/news/articles/\|content/website/news/digital-media/'`; do
echo "Posting $n to LPB";
DATE_STRING=`echo $n | 's/^.*date:\s*//'`;
TITLE_STRING=`cat $n | 's/^.*title:\s*//'`;
TARGET_NEWS_CATEGORY=`echo $n | sed -E 's/.*\/([a-z\-]{1,})\/.*/\1/'`;
SOURCE_STRING=`cat $n | 's/^.*source:\s*//'`;
URL_STRING=`cat $n | 's/^.*url:\s*//'`;
echo "Target URL https://$LPB_HOST/internal/platform-backend/v0/news/categories/$TARGET_NEWS_CATEGORY/items";
curl
--request POST
--header 'Content-Type:application/json'
--header "Authorization:Bearer ${{ env.bearer_token }}"
--data "{\"date\":\"$DATE_STRING\",\"title\":\"$TITLE_STRING\",\"source\":\"$SOURCE_STRING\",\"url\":\"$URL_STRING\"}"
https://$LPB_HOST/internal/platform-backend/v0/news/categories/$TARGET_NEWS_CATEGORY/items;
done;
for n in `cat changed-files/changed-files.txt | grep content/website/news/releases`; do
echo "Posting $n to LPB";
DATE_STRING=`echo $n | 's/^.*date:\s*//'`;
TITLE_STRING=`cat $n | 's/^.*title:\s*//'`;
TARGET_NEWS_CATEGORY=`echo $n | sed -E 's/.*\/([a-z\-]{1,})\/.*/\1/'`;
URL_STRING=`cat $n | 's/^.*url:\s*//'`;
echo "Target URL https://$LPB_HOST/internal/platform-backend/v0/news/categories/$TARGET_NEWS_CATEGORY/items";
curl
--request POST
--header 'Content-Type:application/json'
--header "Authorization:Bearer ${{ env.bearer_token }}"
--data "{\"date\":\"$DATE_STRING\",\"title\":\"$TITLE_STRING\",\"url\":\"$URL_STRING\"}"
https://$LPB_HOST/internal/platform-backend/v0/news/categories/$TARGET_NEWS_CATEGORY/items;
done;
- name: Comment on PR
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'These changes have been pushed to [dev](https://dev-developer.va.gov/about/news).'
})
- name: Previously Merged Warning Comment on PR
if: needs.gather_content.outputs.rename_warning == 'TRUE'
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'If this release note was merged to the `main` branch on another PR, you will need to reach out to [Team Okapi](https://lighthouseva.slack.com/archives/C01931CFMTQ) to remove the copy that remains on the previous date.'
})
send_content_to_production:
name: Send content to production LPB
needs: [gather_content]
environment:
name: production
url: https://developer.va.gov
runs-on: ubuntu-latest
if: needs.gather_content.outputs.target_environment == 'production'
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: NPM install
run: npm ci
- id: get_bearer_token
name: Get Bearer Token
env:
LPB_HOST: "api.va.gov"
LPB_CLIENT_ID: ${{ secrets.LPB_CLIENT_ID }}
LPB_RSA_TOKEN: ${{ secrets.LPB_RSA_SECRET }}
OKTA_TOKEN_AUD: "https://va.okta.com/oauth2/ausdppulkgBFJDZZe297/v1/token"
run: echo "$LPB_RSA_TOKEN" > ./rsa.pem;
ls -la;
wc -l ./rsa.pem;
node ./get-bearer-token.js $LPB_CLIENT_ID ./rsa.pem $LPB_HOST $OKTA_TOKEN_AUD;
BEARER_TOKEN=`cat ./bearer.token`;
echo "bearer_token=$BEARER_TOKEN" >> $GITHUB_ENV;
- name: Get file list
uses: actions/download-artifact@v1
with:
name: changed-files
- name: Send content to production
env:
LPB_HOST: "api.va.gov"
run:
for n in `cat changed-files/changed-files.txt | grep 'content/website/news/articles/\|content/website/news/digital-media/'`; do
echo "Posting $n to LPB";
DATE_STRING=`echo $n | 's/^.*date:\s*//'`;
TITLE_STRING=`cat $n | 's/^.*title:\s*//'`;
TARGET_NEWS_CATEGORY=`echo $n | sed -E 's/.*\/([a-z\-]{1,})\/.*/\1/'`;
SOURCE_STRING=`cat $n | 's/^.*source:\s*//'`;
URL_STRING=`cat $n | 's/^.*url:\s*//'`;
echo "Target URL https://$LPB_HOST/internal/platform-backend/v0/news/categories/$TARGET_NEWS_CATEGORY/items";
curl
--request POST
--header 'Content-Type:application/json'
--header "Authorization:Bearer ${{ env.bearer_token }}"
--data "{\"date\":\"$DATE_STRING\",\"title\":\"$TITLE_STRING\",\"source\":\"$SOURCE_STRING\",\"url\":\"$URL_STRING\"}"
https://$LPB_HOST/internal/platform-backend/v0/news/categories/$TARGET_NEWS_CATEGORY/items;
done;
for n in `cat changed-files/changed-files.txt | grep content/website/news/releases`; do
echo "Posting $n to LPB";
DATE_STRING=`echo $n | 's/^.*date:\s*//'`;
TITLE_STRING=`cat $n | 's/^.*title:\s*//'`;
TARGET_NEWS_CATEGORY=`echo $n | sed -E 's/.*\/([a-z\-]{1,})\/.*/\1/'`;
URL_STRING=`cat $n | 's/^.*url:\s*//'`;
echo "Target URL https://$LPB_HOST/internal/platform-backend/v0/news/categories/$TARGET_NEWS_CATEGORY/items";
curl
--request POST
--header 'Content-Type:application/json'
--header "Authorization:Bearer ${{ env.bearer_token }}"
--data "{\"date\":\"$DATE_STRING\",\"title\":\"$TITLE_STRING\",\"url\":\"$URL_STRING\"}"
https://$LPB_HOST/internal/platform-backend/v0/news/categories/$TARGET_NEWS_CATEGORY/items;
done;
- name: Comment on PR
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'These changes have been pushed to [production](https://developer.va.gov/about/news).'
})