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

api 44751v2 #238

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
302 changes: 199 additions & 103 deletions .github/workflows/send-to-lpb.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
name: Post content to Lighthouse Platform Backend (LPB)

# FIXME: Not sure where this should go ...
permissions:
contents: read

on:
pull_request:
types:
Expand All @@ -9,6 +14,7 @@ on:
branches: [main]

jobs:
#####################################################
gather_content:
name: Gather the changed content
runs-on: ubuntu-latest
Expand All @@ -29,110 +35,195 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0

###########################################################
## TDV: working here ...
- id: pr_files
uses: Ana06/[email protected]
uses: hanseltimeindustries/get-changed-files@v1
with:
# Format of the steps output context.
# Can be 'space-delimited', 'csv', or 'json'.
# Default: 'space-delimited'
format: "space-delimited"
filter: "content/**/release-notes/*"

- 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
echo "all"
echo "============="
for changed_file in ${{ steps.pr_files.outputs.all }}; do
echo "${changed_file}"
done

echo
echo "Added/Modified"
echo "=============="
for added_modified_file in ${{ steps.pr_files.outputs.added_modified }}; do
echo "${added_modified_file}"
done

echo
echo "Removed"
echo "======="
for removed_file in ${{ steps.pr_files.outputs.removed }}; do
echo "${removed_file}"
done

echo
echo "Renamed (method not documented)"
echo "==============================="
for renamed_file in ${{ steps.pr_files.outputs.renamed }}; do
echo "${renamed_file}"
done

if [ "${{ steps.pr_files.outputs.added_modified }}" != "" ]; then
touch changed-files.txt
for f in `echo "${{ steps.pr_files.outputs.added_modified_renamed }}"`; do
for f in `echo "${{ steps.pr_files.outputs.added_modified }}"`; do
echo $f >> changed-files.txt
done
fi

if [ "${{ steps.pr_files.outputs.removed }}" != "" ]; then
touch removed-files.txt
for f in `echo "${{ steps.pr_files.outputs.removed }}"`; do
echo $f >> removed-files.txt
done
fi

# SMELL: may not be necessary
if [ "${{ steps.pr_files.outputs.renamed }}" != "" ]; then
echo "rename_warning=TRUE" >> $GITHUB_OUTPUT
fi
echo "Expected files changes:"

echo
echo "These files were changed:"
cat changed-files.txt

echo
echo "These files were removed:"
cat removed-files.txt

- name: Save changed files list
uses: actions/upload-artifact@v4
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@v4
with:
fetch-depth: 0
- name: NPM install
run: npm ci
- id: get_bearer_token
if: github.actor != 'dependabot[bot]'
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@v4
if: github.actor != 'dependabot[bot]'
with:
name: changed-files
- name: Send content to development
if: github.actor != 'dependabot[bot]'
env:
LPB_HOST: 'dev-api.va.gov'
run:
for n in `cat changed-files.txt | grep content/`; do
echo "Posting $n to LPB";
DATE_STRING=`echo $n | sed 's/[\/\.a-z\-]//g' | sed -E 's/([0-9]{4})([0-9]{2})([0-9]{2})/\1-\2-\3/'`;
CONTENT_STRING=`cat $n | base64 -w 0`;
TARGET_API=`echo $n | sed -E 's/.*\/([a-z\-]{1,})\/release-notes.*/\1/'`;
echo "Target URL https://$LPB_HOST/internal/platform-backend/v0/providers/$TARGET_API/release-notes";
curl
--request POST
--header 'Content-Type:application/json'
--header "Authorization:Bearer ${{ env.bearer_token }}"
--data "{\"date\":\"$DATE_STRING\",\"content\":\"base64:$CONTENT_STRING\"}"
https://$LPB_HOST/internal/platform-backend/v0/providers/$TARGET_API/release-notes;
done;
- name: Comment on PR
uses: actions/github-script@v7
if: github.actor != 'dependabot[bot]'
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/).'
})
- name: Previously Merged Warning Comment on PR
uses: actions/github-script@v7
if: |
needs.gather_content.outputs.rename_warning == 'TRUE' &&
github.actor != 'dependabot[bot]'

- name: Save removed files list
uses: actions/upload-artifact@v4
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.'
})
name: removed-files
path: removed-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@v4
# with:
# fetch-depth: 0

# - name: NPM install
# run: npm ci

# - id: get_bearer_token
# if: github.actor != 'dependabot[bot]'
# 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 changed file list
# uses: actions/download-artifact@v4
# if: github.actor != 'dependabot[bot]'
# with:
# name: changed-files

# - name: Send content to development
# if: github.actor != 'dependabot[bot]'
# env:
# LPB_HOST: 'dev-api.va.gov'
# run:
# for n in `cat changed-files.txt | grep content/`; do
# echo "Posting $n to LPB";

# # TDV: remove lowercase characters and the period and a dash
# # resulting in YYYYMMDD and then inserts dashes
# # resulting in YYYY-MM-DD in the $DATE_STRING
# DATE_STRING=`echo $n | \
# sed 's/[\/\.a-z\-]//g' | \
# sed -E 's/([0-9]{4})([0-9]{2})([0-9]{2})/\1-\2-\3/'`;

# CONTENT_STRING=`cat $n | base64 -w 0`;

# # The command extracts the portion of the string in `$n` that matches the pattern `/<something>/release-notes`, capturing the
# # `<something>` part (consisting of lowercase letters and hyphens) and assigns it to the variable `TARGET_API`.

# TARGET_API=`echo $n | sed -E 's/.*\/([a-z\-]{1,})\/release-notes.*/\1/'`;

# echo "Target URL https://$LPB_HOST/internal/platform-backend/v0/providers/$TARGET_API/release-notes";

# curl
# --request POST
# --header 'Content-Type:application/json'
# --header "Authorization:Bearer ${{ env.bearer_token }}"
# --data "{\"date\":\"$DATE_STRING\",\"content\":\"base64:$CONTENT_STRING\"}"
# https://$LPB_HOST/internal/platform-backend/v0/providers/$TARGET_API/release-notes;
# done;

# # TODO: Add code to send a DELETE action to the backend to remove deleted
# # release notes.

# - name: Comment on PR
# uses: actions/github-script@v7
# if: github.actor != 'dependabot[bot]'
# 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/).'
# })

# - name: Previously Merged Warning Comment on PR
# uses: actions/github-script@v7
# if: |
# needs.gather_content.outputs.rename_warning == 'TRUE' &&
# github.actor != 'dependabot[bot]'
# 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:
environment:
name: production
url: https://developer.va.gov
runs-on: ubuntu-latest
Expand All @@ -142,46 +233,49 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: NPM install
run: npm ci

- id: get_bearer_token
if: github.actor != 'dependabot[bot]'
name: Get Bearer Token
env:
LPB_HOST: 'api.va.gov'
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;
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@v4
if: github.actor != 'dependabot[bot]'
with:
name: changed-files

- name: Send content to production
env:
LPB_HOST: 'api.va.gov'
LPB_HOST: "api.va.gov"
if: github.actor != 'dependabot[bot]'
run:
for n in `cat changed-files.txt | grep content/`; do
echo "Posting $n to LPB";
DATE_STRING=`echo $n | sed 's/[\/\.a-z\-]//g' | sed -E 's/([0-9]{4})([0-9]{2})([0-9]{2})/\1-\2-\3/'`;
CONTENT_STRING=`cat $n | base64 -w 0`;
TARGET_API=`echo $n | sed -E 's/.*\/([a-z\-]{1,})\/release-notes.*/\1/'`;
echo "Target URL https://$LPB_HOST/internal/platform-backend/v0/providers/$TARGET_API/release-notes";
curl
--request POST
--header 'Content-Type:application/json'
--header "Authorization:Bearer ${{ env.bearer_token }}"
--data "{\"date\":\"$DATE_STRING\",\"content\":\"base64:$CONTENT_STRING\"}"
https://$LPB_HOST/internal/platform-backend/v0/providers/$TARGET_API/release-notes;
run: for n in `cat changed-files.txt | grep content/`; do
echo "Posting $n to LPB";
DATE_STRING=`echo $n | sed 's/[\/\.a-z\-]//g' | sed -E 's/([0-9]{4})([0-9]{2})([0-9]{2})/\1-\2-\3/'`;
CONTENT_STRING=`cat $n | base64 -w 0`;
TARGET_API=`echo $n | sed -E 's/.*\/([a-z\-]{1,})\/release-notes.*/\1/'`;
echo "Target URL https://$LPB_HOST/internal/platform-backend/v0/providers/$TARGET_API/release-notes";
curl
--request POST
--header 'Content-Type:application/json'
--header "Authorization:Bearer ${{ env.bearer_token }}"
--data "{\"date\":\"$DATE_STRING\",\"content\":\"base64:$CONTENT_STRING\"}"
https://$LPB_HOST/internal/platform-backend/v0/providers/$TARGET_API/release-notes;
done;

- name: Comment on PR
uses: actions/github-script@v7
if: github.actor != 'dependabot[bot]'
Expand All @@ -193,6 +287,8 @@ jobs:
repo: context.repo.repo,
body: 'These changes have been pushed to [production](https://developer.va.gov/).'
})

#####################################################
send_notifications:
name: Send Slack notification for newly published release notes
needs: [gather_content, send_content_to_production]
Expand All @@ -215,13 +311,13 @@ jobs:
# In practice this should only have a single API per merged
# release note but because there isn't a technical limitation
# that means it can't we need to build it to support multiples

# Empty string of URLs with new release notes
URLS=""

# Download legacy.json file so we can get the url_slugs
wget -O legacy.json https://developer.va.gov/platform-backend/v0/providers/transformations/legacy.json?environment=sandbox

# Loop over the list of changed release note files
for n in `cat changed-files.txt | grep content/ | grep release-notes`; do
TARGET_API=`echo $n | sed -E 's/.*\/([a-z\-]{1,})\/release-notes.*/\1/'`;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello world
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello world
Loading