Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workflows to post news #125

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
219 changes: 219 additions & 0 deletions .github/workflows/news-post-lpb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,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.'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be updated to reference it being news, not release notes. Also the ending of this error talks about the date. Are we doing any deduplication of news posts on the LPB side? Would this error ever hit?

})
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).'
})
162 changes: 162 additions & 0 deletions .github/workflows/news-seed-lpb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
name: Seed all news to Lighthouse Platform Backend (LPB)
on:
workflow_dispatch:
inputs:
environment:
description: "What environment are you seeding?"
required: true
type: environment

jobs:
gather_content:
name: Gather all content
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Find files and artifact them
run: |
find ./content/website -type f > seed-files.txt
echo "All files to upload:"
cat seed-files.txt
- name: Save changed files list
uses: actions/upload-artifact@v1
with:
name: seed-files
path: seed-files.txt
send_content_to_development:
name: Send content to development Lighthouse Platform Backend (LPB)
needs: [gather_content]
environment:
name: development
url: https://dev-developer.va.gov
runs-on: ubuntu-latest
if: ${{ inputs.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;
echo "::set-output name=bearer_token::$BEARER_TOKEN"
- name: Get file list
uses: actions/download-artifact@v1
with:
name: seed-files
- name: Seed content to development
env:
LPB_HOST: "dev-api.va.gov"
BEARER_TOKEN: ${{ steps.get_bearer_token.outputs.bearer_token }}
run:
for n in `cat seed-files/seed-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;
send_content_to_production:
name: Send content to production Lighthouse Platform Backend (LPB)
needs: [gather_content]
environment:
name: production
url: https://developer.va.gov
runs-on: ubuntu-latest
if: ${{ inputs.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;
echo "::set-output name=bearer_token::$BEARER_TOKEN"
- name: Get file list
uses: actions/download-artifact@v1
with:
name: seed-files
- name: Seed content to production
env:
LPB_HOST: "api.va.gov"
BEARER_TOKEN: ${{ steps.get_bearer_token.outputs.bearer_token }}
run:
for n in `cat seed-files/seed-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;
Loading