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-44751 Testing environment contents #232

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
ee0f6b0
API-44751 Testing environment contents
SloopKoning Feb 14, 2025
6d77e82
fixed things that were not shell commands into variables?
SloopKoning Feb 14, 2025
f7d7ad2
changed name of an existing release note
SloopKoning Feb 14, 2025
6c48388
restored real file content and name; explicitely git rm on test file
SloopKoning Feb 14, 2025
c85e889
deleted an existing release note after making a backup
SloopKoning Feb 14, 2025
c7843be
restored existing real file; added a new test file to test git diff s…
SloopKoning Feb 14, 2025
2cd1892
testing a git status way of identifying changed files
SloopKoning Feb 14, 2025
7ae9e29
the git status approach may not work
SloopKoning Feb 14, 2025
6b7dfd2
added an old file and renamed and modified an old file
SloopKoning Feb 15, 2025
e824f90
Add script to analyze unique changes in the current Git branch
SloopKoning Feb 15, 2025
bf48a02
Refactor file change detection to use external script
SloopKoning Feb 15, 2025
235db4e
Ignore non-content filepaths in changed_files.sh
SloopKoning Feb 15, 2025
c1bd39b
updated script to write changed and deleted filepaths to different te…
SloopKoning Feb 17, 2025
31d86df
restored content to match the main branch
SloopKoning Feb 17, 2025
a30d83f
added error and warn functions to script
SloopKoning Feb 17, 2025
6ac0964
changed function name from warning to warn
SloopKoning Feb 17, 2025
1ab9880
removed improper sed based regex property
SloopKoning Feb 17, 2025
61229c8
getting rid of bash syntax in favor of pure SH
SloopKoning Feb 17, 2025
01fa2f0
changed file names to match current conventions; replaced old gather …
SloopKoning Feb 17, 2025
051a072
started the integration of the deleted files into the GH workflow
SloopKoning Feb 17, 2025
02c86bb
workflow was reporting that deleted-files.txt did not existl maybe th…
SloopKoning Feb 17, 2025
45046b9
API-44751 Update SendToLPB Workflow
SloopKoning Feb 18, 2025
ab1203e
API-44751 Update SendToLPB Workflow
SloopKoning Feb 20, 2025
f70adeb
API-44751 missed this file
SloopKoning Feb 20, 2025
811235b
API-44751 Update SendToLPB Workflow
SloopKoning Feb 20, 2025
53fafae
API-44751 Testing with get raw git diff inside GH actions
SloopKoning Feb 20, 2025
76c4524
API-44751 updated to get rid of old way of doing stuff
SloopKoning Feb 20, 2025
2dd5659
snapshot
SloopKoning Feb 20, 2025
ae5c088
zeroing in on a solution
SloopKoning Feb 20, 2025
1bc3dd2
API-44751 Update Checkout and Diff Logic
SloopKoning Feb 20, 2025
5651e40
snapshot testing
SloopKoning Feb 20, 2025
1ffa2b6
snapshot testing
SloopKoning Feb 20, 2025
66de09b
snapshot testing
SloopKoning Feb 20, 2025
4098e3b
snapshot testing darn -- name things; also dump_env.sh did not have i…
SloopKoning Feb 21, 2025
f5323c3
snapshot testing
SloopKoning Feb 21, 2025
1acee40
snapshot - wrong indention in yaml file
SloopKoning Feb 21, 2025
a34a7b0
snapshot - testing - forgot the pipe on a multi-line run block
SloopKoning Feb 21, 2025
67b2c4d
added content/ filter
SloopKoning Feb 21, 2025
4749f44
found another syntax error
SloopKoning Feb 21, 2025
8bc3e13
snapshot - trying a different way more safely filter content/
SloopKoning Feb 21, 2025
b04d945
snapshot - found an empty file problem
SloopKoning Feb 21, 2025
c0214e6
snapshot - testing reveal more bash contamination in the SH script
SloopKoning Feb 21, 2025
db003a9
snapshot resorting to real basic stuff to parse a git diff raw line
SloopKoning Feb 21, 2025
7c5405c
snapshot - fixed non posix compliant sh thing
SloopKoning Feb 21, 2025
8e6f5ad
snapshot - testing rename and add inside of content
SloopKoning Feb 21, 2025
cbcef9e
API-44751 Remove Unused Workflow Established Consistent Pattern
SloopKoning Feb 21, 2025
84653b2
snapshot - should be last test <fingers crossed>
SloopKoning Feb 21, 2025
57f3538
API-44751 changed step names to avoid confusion
SloopKoning Feb 21, 2025
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
243 changes: 191 additions & 52 deletions .github/workflows/send-to-lpb.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
name: Post content to Lighthouse Platform Backend (LPB)

# This GitHub Actions workflow is designed to facilitate the seeding of release
# notes to the Lighthouse Platform Backend (LPB). The process is triggered
# manually and allows you to specify the environment (development or production)
# in which the seeding should occur. The workflow is separated into three main
# jobs:
# * gathering content,
# * sending content to the development environment, and
# * sending content to the production environment.
#
# NOTE: deleted files are processed before changed files
# because non-technicals are using the Github UI to
# add, change, rename and delete files. It is possible
# that they could delete an existing release note and
# add a new release note with the same name or date.

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

jobs:

gather_content:
name: Gather the changed content
runs-on: ubuntu-latest
Expand All @@ -25,37 +42,67 @@ jobs:
fi
echo $TARGET_ENVIRONMENT
echo "target_environment=$TARGET_ENVIRONMENT" >> $GITHUB_OUTPUT

- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

##############################
## Global git diff -raw main...

- name: Checkout Main Branch
run: git checkout main

- name: Get Feature Branch Name
id: get-feature-branch
run: |
echo "FEATURE_BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT

- name: Check out Feature Branch
run: git checkout ${{ steps.get-feature-branch.outputs.FEATURE_BRANCH }}

- name: Get Raw Diff and Write to File
run: |
DIFF=$(git diff --raw main...${{ steps.get-feature-branch.outputs.FEATURE_BRANCH }})
echo "$DIFF" > raw_diff.txt

- name: Output Diff (Example - Read from File)
run: |
echo "Raw Diff (from file):"
cat raw_diff.txt

- id: pr_files
uses: Ana06/[email protected]
run: |
chmod +x bin/actions/changed_files.sh
sh bin/actions/changed_files.sh

- 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:"
echo "Changed files:"
cat changed-files.txt
#
echo "Deleted files:"
cat deleted-files.txt

- name: Save changed files list
uses: actions/upload-artifact@v4
with:
name: changed-files
path: changed-files.txt

- name: Save deleted files list
uses: actions/upload-artifact@v4
with:
name: deleted-files
path: deleted-files.txt

send_content_to_development:
name: Send content to development LPB
needs: [gather_content]
environment:
environment:
name: development
url: https://dev-developer.va.gov
runs-on: ubuntu-latest
Expand All @@ -65,8 +112,10 @@ 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
Expand All @@ -75,36 +124,76 @@ jobs:
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:
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

#############################
## Development ##
## Processed Deleted Files ##
#############################

- name: Get deleted files list
uses: actions/download-artifact@v4
if: github.actor != 'dependabot[bot]'
with:
name: deleted-files

- name: Send deleted files to development
if: github.actor != 'dependabot[bot]'
env:
LPB_HOST: 'dev-api.va.gov'
run: |
# SAFE WAY TO ITERATE LINES - Handles spaces in filenames
while IFS= read -r n; do
echo "DEV: Deleting $n from LPB";
DATE_STRING=$(basename -- "$n" | grep -oE '[0-9]{4}-[0-9]{2}-[0-9]{2}')
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 DELETE \
--header 'Content-Type:application/json' \
--header "Authorization:Bearer ${{ env.bearer_token }}" \
--data "{\"date\":\"$DATE_STRING\"}" \
"https://$LPB_HOST/internal/platform-backend/v0/providers/$TARGET_API/release-notes";
done < deleted-files.txt

#############################
## Development ##
## Processed Changed Files ##
#############################

- name: Get changed files list
uses: actions/download-artifact@v4
if: github.actor != 'dependabot[bot]'
with:
name: changed-files
- name: Send content to development

- name: Send changed 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
run: |
# SAFE WAY TO ITERATE LINES - Handles spaces in filenames
while IFS= read -r n; do
# ignore the file if it does not exist or is not readable
[ -r "$n" ] || continue

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/'`;
DATE_STRING=$(basename -- "$n" | grep -oE '[0-9]{4}-[0-9]{2}-[0-9]{2}')
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;
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 < changed-files.txt

- name: Comment on PR
uses: actions/github-script@v7
if: github.actor != 'dependabot[bot]'
Expand All @@ -116,6 +205,7 @@ jobs:
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: |
Expand All @@ -129,10 +219,11 @@ jobs:
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,8 +233,10 @@ 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
Expand All @@ -152,36 +245,78 @@ jobs:
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:
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

#############################
## Production ##
## Processed Deleted Files ##
#############################

- name: Get deleted files list
uses: actions/download-artifact@v4
if: github.actor != 'dependabot[bot]'
with:
name: deleted-files

- name: Send deleted files to production
if: github.actor != 'dependabot[bot]'
env:
LPB_HOST: 'api.va.gov'
run: |
# SAFE WAY TO ITERATE LINES - Handles spaces in filenames
while IFS= read -r n; do
echo "PROD: Deleting $n from LPB";
DATE_STRING=$(basename -- "$n" | grep -oE '[0-9]{4}-[0-9]{2}-[0-9]{2}')
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 DELETE \
--header 'Content-Type:application/json' \
--header "Authorization:Bearer ${{ env.bearer_token }}" \
--data "{\"date\":\"$DATE_STRING\"}" \
"https://$LPB_HOST/internal/platform-backend/v0/providers/$TARGET_API/release-notes";
done < deleted-files.txt


#############################
## Production ##
## Processed Changed Files ##
#############################

- name: Get changed files list
uses: actions/download-artifact@v4
if: github.actor != 'dependabot[bot]'
with:
name: changed-files
- name: Send content to production

- name: Send changed files to production
env:
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;
done;
run: |
# SAFE WAY TO ITERATE LINES - Handles spaces in filenames
while IFS= read -r n; do
# ignore the file if it does not exist or is not readable
[ -r "$n" ] || continue
if [[ "$n" == *'content/'* ]]; then
echo "Posting $n to LPB";
DATE_STRING=$(basename -- "$n" | grep -oE '[0-9]{4}-[0-9]{2}-[0-9]{2}')
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";
fi
done < changed-files.txt

- name: Comment on PR
uses: actions/github-script@v7
if: github.actor != 'dependabot[bot]'
Expand All @@ -193,6 +328,7 @@ 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 Down Expand Up @@ -223,12 +359,15 @@ jobs:
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/'`;
TARGET_API_NAME=`jq -r ".[].apis[] | select(.altID==\"$TARGET_API\" or .urlSlug==\"$TARGET_API\") | .name" legacy.json`;
TARGET_URL_SLUG=`jq -r ".[].apis[] | select(.altID==\"$TARGET_API\" or .urlSlug==\"$TARGET_API\") | .urlSlug" legacy.json`;
URLS+="[$TARGET_API_NAME release notes](https://developer.va.gov/explore/api/$TARGET_URL_SLUG/release-notes)\n";
done
# SAFE WAY TO ITERATE LINES - Handles spaces in filenames
while IFS= read -r n; do
if [[ "$n" == *'content/'* ]] && [[ "$n" == *'release-notes'* ]]; then
TARGET_API=$(echo "$n" | sed -E 's/.*\/([a-z\-]{1,})\/release-notes.*/\1/');
TARGET_API_NAME=$(jq -r ".[].apis[] | select(.altID==\"$TARGET_API\" or .urlSlug==\"$TARGET_API\") | .name" legacy.json);
TARGET_URL_SLUG=$(jq -r ".[].apis[] | select(.altID==\"$TARGET_API\" or .urlSlug==\"$TARGET_API\") | .urlSlug" legacy.json);
URLS+="[$TARGET_API_NAME release notes](https://developer.va.gov/explore/api/$TARGET_URL_SLUG/release-notes)\n";
fi
done < changed-files.txt
echo "URLs: $URLS"
echo "urls=${URLS}" >> $GITHUB_OUTPUT
- name: Send Slack notification on success
Expand Down
Loading
Loading