From 428df46a063f406ed5dedd7f9a83827585fd4b25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Rivera=20Toro?= Date: Tue, 26 Mar 2024 11:09:28 -0400 Subject: [PATCH 01/12] Add workflows to post news --- .github/workflows/news-post-lpb.yml | 219 ++++++++++++++++++ .github/workflows/news-seed-lpb.yml | 162 +++++++++++++ ...o-lpb.yaml => release-notes-post-lpb.yaml} | 80 +++---- ...f-lpb.yaml => release-notes-seed-lpb.yaml} | 80 +++---- 4 files changed, 459 insertions(+), 82 deletions(-) create mode 100644 .github/workflows/news-post-lpb.yml create mode 100644 .github/workflows/news-seed-lpb.yml rename .github/workflows/{send-to-lpb.yaml => release-notes-post-lpb.yaml} (69%) rename .github/workflows/{full-seeding-of-lpb.yaml => release-notes-seed-lpb.yaml} (56%) diff --git a/.github/workflows/news-post-lpb.yml b/.github/workflows/news-post-lpb.yml new file mode 100644 index 00000000..f8f7de12 --- /dev/null +++ b/.github/workflows/news-post-lpb.yml @@ -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/get-changed-files@v2.2.0 + 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 | sed 's/[\/\.a-z\-]//g' | sed -E 's/([0-9]{4})([0-9]{2})([0-9]{2})/\1-\2-\3/'`; + 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 | sed 's/[\/\.a-z\-]//g' | sed -E 's/([0-9]{4})([0-9]{2})([0-9]{2})/\1-\2-\3/'`; + 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 | sed 's/[\/\.a-z\-]//g' | sed -E 's/([0-9]{4})([0-9]{2})([0-9]{2})/\1-\2-\3/'`; + 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 | sed 's/[\/\.a-z\-]//g' | sed -E 's/([0-9]{4})([0-9]{2})([0-9]{2})/\1-\2-\3/'`; + 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/release-notes/).' + }) diff --git a/.github/workflows/news-seed-lpb.yml b/.github/workflows/news-seed-lpb.yml new file mode 100644 index 00000000..526c9c4d --- /dev/null +++ b/.github/workflows/news-seed-lpb.yml @@ -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 | sed 's/[\/\.a-z\-]//g' | sed -E 's/([0-9]{4})([0-9]{2})([0-9]{2})/\1-\2-\3/'`; + 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 | sed 's/[\/\.a-z\-]//g' | sed -E 's/([0-9]{4})([0-9]{2})([0-9]{2})/\1-\2-\3/'`; + 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 | sed 's/[\/\.a-z\-]//g' | sed -E 's/([0-9]{4})([0-9]{2})([0-9]{2})/\1-\2-\3/'`; + 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 | sed 's/[\/\.a-z\-]//g' | sed -E 's/([0-9]{4})([0-9]{2})([0-9]{2})/\1-\2-\3/'`; + 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; diff --git a/.github/workflows/send-to-lpb.yaml b/.github/workflows/release-notes-post-lpb.yaml similarity index 69% rename from .github/workflows/send-to-lpb.yaml rename to .github/workflows/release-notes-post-lpb.yaml index 31ae31d1..c5a838dc 100644 --- a/.github/workflows/send-to-lpb.yaml +++ b/.github/workflows/release-notes-post-lpb.yaml @@ -1,4 +1,4 @@ -name: Post content to Lighthouse Platform Backend (LPB) +name: Post release notes to Lighthouse Platform Backend (LPB) on: pull_request: types: @@ -7,6 +7,8 @@ on: - reopened - closed branches: [main] + paths-ignore: + - "content/website/**" jobs: gather_content: @@ -31,6 +33,8 @@ jobs: fetch-depth: 0 - id: pr_files uses: Ana06/get-changed-files@v2.2.0 + with: + filter: "!content/website/**" - id: upload_content name: Find files and send them continue-on-error: true @@ -55,7 +59,7 @@ jobs: 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 @@ -70,12 +74,11 @@ jobs: - id: get_bearer_token name: Get Bearer Token env: - LPB_HOST: 'dev-api.va.gov' + 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; + 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; @@ -87,20 +90,19 @@ jobs: 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/`; 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; + LPB_HOST: "dev-api.va.gov" + run: for n in `cat changed-files/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@v6 @@ -126,7 +128,7 @@ jobs: 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 @@ -141,12 +143,11 @@ jobs: - id: get_bearer_token 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; @@ -158,20 +159,19 @@ jobs: 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/`; 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; + LPB_HOST: "api.va.gov" + run: for n in `cat changed-files/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@v6 @@ -182,4 +182,4 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, body: 'These changes have been pushed to [production](https://developer.va.gov/release-notes/).' - }) \ No newline at end of file + }) diff --git a/.github/workflows/full-seeding-of-lpb.yaml b/.github/workflows/release-notes-seed-lpb.yaml similarity index 56% rename from .github/workflows/full-seeding-of-lpb.yaml rename to .github/workflows/release-notes-seed-lpb.yaml index 63d95e15..fdd8bdd3 100644 --- a/.github/workflows/full-seeding-of-lpb.yaml +++ b/.github/workflows/release-notes-seed-lpb.yaml @@ -3,7 +3,7 @@ on: workflow_dispatch: inputs: environment: - description: 'What environment are you seeding?' + description: "What environment are you seeding?" required: true type: environment @@ -18,7 +18,7 @@ jobs: fetch-depth: 0 - name: Find files and artifact them run: | - find ./content -type f > seed-files.txt + find ./content -type f -not -path "./content/website/*" > seed-files.txt echo "All files to upload:" cat seed-files.txt - name: Save changed files list @@ -29,7 +29,7 @@ jobs: send_content_to_development: name: Send content to development Lighthouse Platform Backend (LPB) needs: [gather_content] - environment: + environment: name: development url: https://dev-developer.va.gov runs-on: ubuntu-latest @@ -44,12 +44,11 @@ jobs: - id: get_bearer_token name: Get Bearer Token env: - LPB_HOST: 'dev-api.va.gov' + 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; + 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; @@ -62,27 +61,26 @@ jobs: name: seed-files - name: Seed content to development env: - LPB_HOST: 'dev-api.va.gov' + 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/`; 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 $BEARER_TOKEN" - --data "{\"date\":\"$DATE_STRING\",\"content\":\"base64:$CONTENT_STRING\"}" - https://$LPB_HOST/internal/platform-backend/v0/providers/$TARGET_API/release-notes; - sleep 1; + run: for n in `cat seed-files/seed-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 $BEARER_TOKEN" + --data "{\"date\":\"$DATE_STRING\",\"content\":\"base64:$CONTENT_STRING\"}" + https://$LPB_HOST/internal/platform-backend/v0/providers/$TARGET_API/release-notes; + sleep 1; done; send_content_to_production: name: Send content to production Lighthouse Platform Backend (LPB) needs: [gather_content] - environment: + environment: name: production url: https://developer.va.gov runs-on: ubuntu-latest @@ -97,12 +95,11 @@ jobs: - id: get_bearer_token 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; @@ -115,20 +112,19 @@ jobs: name: seed-files - name: Seed content to production env: - LPB_HOST: 'api.va.gov' + 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/`; 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 $BEARER_TOKEN" - --data "{\"date\":\"$DATE_STRING\",\"content\":\"base64:$CONTENT_STRING\"}" - https://$LPB_HOST/internal/platform-backend/v0/providers/$TARGET_API/release-notes; - sleep 1; + run: for n in `cat seed-files/seed-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 $BEARER_TOKEN" + --data "{\"date\":\"$DATE_STRING\",\"content\":\"base64:$CONTENT_STRING\"}" + https://$LPB_HOST/internal/platform-backend/v0/providers/$TARGET_API/release-notes; + sleep 1; done; From 9d4553b8e94cc0e4f6bc1b18e973de1592b6bef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Rivera=20Toro?= Date: Tue, 26 Mar 2024 11:39:21 -0400 Subject: [PATCH 02/12] Update branch name --- .github/workflows/news-post-lpb.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/news-post-lpb.yml b/.github/workflows/news-post-lpb.yml index f8f7de12..703c6f4b 100644 --- a/.github/workflows/news-post-lpb.yml +++ b/.github/workflows/news-post-lpb.yml @@ -6,7 +6,7 @@ on: - synchronize - reopened - closed - branches: [main] + branches: [api-22679-news] paths: - "content/website/**" From 907e408124ad77064effcdcc9d176e3ae667d665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Rivera=20Toro?= Date: Tue, 26 Mar 2024 11:42:54 -0400 Subject: [PATCH 03/12] Revert branch name change --- .github/workflows/news-post-lpb.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/news-post-lpb.yml b/.github/workflows/news-post-lpb.yml index 703c6f4b..f8f7de12 100644 --- a/.github/workflows/news-post-lpb.yml +++ b/.github/workflows/news-post-lpb.yml @@ -6,7 +6,7 @@ on: - synchronize - reopened - closed - branches: [api-22679-news] + branches: [main] paths: - "content/website/**" From c08b7c3ce36ebc41aa2b9c2e09e936491152c7ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Rivera=20Toro?= Date: Tue, 26 Mar 2024 11:51:40 -0400 Subject: [PATCH 04/12] Use date from content --- .github/workflows/news-post-lpb.yml | 8 ++++---- .github/workflows/news-seed-lpb.yml | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/news-post-lpb.yml b/.github/workflows/news-post-lpb.yml index f8f7de12..dd1b0a27 100644 --- a/.github/workflows/news-post-lpb.yml +++ b/.github/workflows/news-post-lpb.yml @@ -94,7 +94,7 @@ jobs: 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 | sed 's/[\/\.a-z\-]//g' | sed -E 's/([0-9]{4})([0-9]{2})([0-9]{2})/\1-\2-\3/'`; + 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*//'`; @@ -109,7 +109,7 @@ jobs: 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 | sed 's/[\/\.a-z\-]//g' | sed -E 's/([0-9]{4})([0-9]{2})([0-9]{2})/\1-\2-\3/'`; + 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*//'`; @@ -180,7 +180,7 @@ jobs: 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 | sed 's/[\/\.a-z\-]//g' | sed -E 's/([0-9]{4})([0-9]{2})([0-9]{2})/\1-\2-\3/'`; + 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*//'`; @@ -195,7 +195,7 @@ jobs: 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 | sed 's/[\/\.a-z\-]//g' | sed -E 's/([0-9]{4})([0-9]{2})([0-9]{2})/\1-\2-\3/'`; + 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*//'`; diff --git a/.github/workflows/news-seed-lpb.yml b/.github/workflows/news-seed-lpb.yml index 526c9c4d..bddc7f82 100644 --- a/.github/workflows/news-seed-lpb.yml +++ b/.github/workflows/news-seed-lpb.yml @@ -66,7 +66,7 @@ jobs: 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 | sed 's/[\/\.a-z\-]//g' | sed -E 's/([0-9]{4})([0-9]{2})([0-9]{2})/\1-\2-\3/'`; + 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*//'`; @@ -81,7 +81,7 @@ jobs: 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 | sed 's/[\/\.a-z\-]//g' | sed -E 's/([0-9]{4})([0-9]{2})([0-9]{2})/\1-\2-\3/'`; + 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*//'`; @@ -133,7 +133,7 @@ jobs: 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 | sed 's/[\/\.a-z\-]//g' | sed -E 's/([0-9]{4})([0-9]{2})([0-9]{2})/\1-\2-\3/'`; + 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*//'`; @@ -148,7 +148,7 @@ jobs: 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 | sed 's/[\/\.a-z\-]//g' | sed -E 's/([0-9]{4})([0-9]{2})([0-9]{2})/\1-\2-\3/'`; + 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*//'`; From d8b0def1c6578b9c84602c59e80d59401f7fccc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Rivera=20Toro?= Date: Wed, 27 Mar 2024 10:44:17 -0400 Subject: [PATCH 05/12] Add path to workflow --- .github/workflows/release-notes-post-lpb.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/release-notes-post-lpb.yaml b/.github/workflows/release-notes-post-lpb.yaml index c5a838dc..bb118e9b 100644 --- a/.github/workflows/release-notes-post-lpb.yaml +++ b/.github/workflows/release-notes-post-lpb.yaml @@ -7,6 +7,8 @@ on: - reopened - closed branches: [main] + paths: + - "content/**" paths-ignore: - "content/website/**" From 053c228acb22d8fc84eed9e7d00341ee7d65c194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Rivera=20Toro?= Date: Wed, 27 Mar 2024 10:47:37 -0400 Subject: [PATCH 06/12] Update comment url --- .github/workflows/news-post-lpb.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/news-post-lpb.yml b/.github/workflows/news-post-lpb.yml index dd1b0a27..b45757b5 100644 --- a/.github/workflows/news-post-lpb.yml +++ b/.github/workflows/news-post-lpb.yml @@ -129,7 +129,7 @@ jobs: 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/).' + 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' @@ -215,5 +215,5 @@ jobs: 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/release-notes/).' + body: 'These changes have been pushed to [production](https://developer.va.gov/about/news).' }) From 054b8722a9854b716ebe60c2fc861119e52152bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Rivera=20Toro?= Date: Thu, 28 Mar 2024 10:22:38 -0400 Subject: [PATCH 07/12] Update text manipulation for category --- .github/workflows/news-post-lpb.yml | 8 ++++---- .github/workflows/news-seed-lpb.yml | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/news-post-lpb.yml b/.github/workflows/news-post-lpb.yml index b45757b5..d79eb199 100644 --- a/.github/workflows/news-post-lpb.yml +++ b/.github/workflows/news-post-lpb.yml @@ -96,7 +96,7 @@ jobs: 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/'`; + TARGET_NEWS_CATEGORY=`echo $n | sed -E 's/.*\/([a-z\-]{1,})\/.*/\1/' | sed 's/^./\U&/;s/-/ /g'`; 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"; @@ -111,7 +111,7 @@ jobs: 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/'`; + TARGET_NEWS_CATEGORY=`echo $n | sed -E 's/.*\/([a-z\-]{1,})\/.*/\1/' | sed 's/^./\U&/;s/-/ /g'`; URL_STRING=`cat $n | 's/^.*url:\s*//'`; echo "Target URL https://$LPB_HOST/internal/platform-backend/v0/news/categories/$TARGET_NEWS_CATEGORY/items"; curl @@ -182,7 +182,7 @@ jobs: 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/'`; + TARGET_NEWS_CATEGORY=`echo $n | sed -E 's/.*\/([a-z\-]{1,})\/.*/\1/' | sed 's/^./\U&/;s/-/ /g'`; 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"; @@ -197,7 +197,7 @@ jobs: 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/'`; + TARGET_NEWS_CATEGORY=`echo $n | sed -E 's/.*\/([a-z\-]{1,})\/.*/\1/' | sed 's/^./\U&/;s/-/ /g'`; URL_STRING=`cat $n | 's/^.*url:\s*//'`; echo "Target URL https://$LPB_HOST/internal/platform-backend/v0/news/categories/$TARGET_NEWS_CATEGORY/items"; curl diff --git a/.github/workflows/news-seed-lpb.yml b/.github/workflows/news-seed-lpb.yml index bddc7f82..296cc114 100644 --- a/.github/workflows/news-seed-lpb.yml +++ b/.github/workflows/news-seed-lpb.yml @@ -68,7 +68,7 @@ jobs: 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/'`; + TARGET_NEWS_CATEGORY=`echo $n | sed -E 's/.*\/([a-z\-]{1,})\/.*/\1/' | sed 's/^./\U&/;s/-/ /g'`; 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"; @@ -83,7 +83,7 @@ jobs: 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/'`; + TARGET_NEWS_CATEGORY=`echo $n | sed -E 's/.*\/([a-z\-]{1,})\/.*/\1/' | sed 's/^./\U&/;s/-/ /g'`; URL_STRING=`cat $n | 's/^.*url:\s*//'`; echo "Target URL https://$LPB_HOST/internal/platform-backend/v0/news/categories/$TARGET_NEWS_CATEGORY/items"; curl @@ -135,7 +135,7 @@ jobs: 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/'`; + TARGET_NEWS_CATEGORY=`echo $n | sed -E 's/.*\/([a-z\-]{1,})\/.*/\1/' | sed 's/^./\U&/;s/-/ /g'`; 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"; @@ -150,7 +150,7 @@ jobs: 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/'`; + TARGET_NEWS_CATEGORY=`echo $n | sed -E 's/.*\/([a-z\-]{1,})\/.*/\1/' | sed 's/^./\U&/;s/-/ /g'`; URL_STRING=`cat $n | 's/^.*url:\s*//'`; echo "Target URL https://$LPB_HOST/internal/platform-backend/v0/news/categories/$TARGET_NEWS_CATEGORY/items"; curl From 94ff51226b862b97e4c4f26928dd6483ee39dbd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Rivera=20Toro?= Date: Thu, 28 Mar 2024 11:58:55 -0400 Subject: [PATCH 08/12] Limit workflow to main branch --- .github/workflows/release-notes-post-lpb.yaml | 5 +++++ .github/workflows/release-notes-seed-lpb.yaml | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/.github/workflows/release-notes-post-lpb.yaml b/.github/workflows/release-notes-post-lpb.yaml index bb118e9b..2d37e19b 100644 --- a/.github/workflows/release-notes-post-lpb.yaml +++ b/.github/workflows/release-notes-post-lpb.yaml @@ -20,6 +20,11 @@ jobs: rename_warning: ${{ steps.get_target_environment.outputs.rename_warning }} target_environment: ${{ steps.get_target_environment.outputs.target_environment }} steps: + - name: Fail if branch is not main + if: github.ref != 'refs/heads/main' + run: | + echo "This workflow should not be triggered with workflow_dispatch on a branch other than main" + exit 1 - id: get_target_environment name: Determine Target Environment run: | diff --git a/.github/workflows/release-notes-seed-lpb.yaml b/.github/workflows/release-notes-seed-lpb.yaml index fdd8bdd3..1cdafa06 100644 --- a/.github/workflows/release-notes-seed-lpb.yaml +++ b/.github/workflows/release-notes-seed-lpb.yaml @@ -12,6 +12,11 @@ jobs: name: Gather all content runs-on: ubuntu-latest steps: + - name: Fail if branch is not main + if: github.ref != 'refs/heads/main' + run: | + echo "This workflow should not be triggered with workflow_dispatch on a branch other than main" + exit 1 - name: Checkout uses: actions/checkout@v2 with: From 375c913758b58cb81a6767f1ad7bdd9754ed0fcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Rivera=20Toro?= Date: Thu, 28 Mar 2024 12:02:15 -0400 Subject: [PATCH 09/12] Fix path --- .github/workflows/release-notes-post-lpb.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/release-notes-post-lpb.yaml b/.github/workflows/release-notes-post-lpb.yaml index 2d37e19b..f8a5ce12 100644 --- a/.github/workflows/release-notes-post-lpb.yaml +++ b/.github/workflows/release-notes-post-lpb.yaml @@ -9,8 +9,7 @@ on: branches: [main] paths: - "content/**" - paths-ignore: - - "content/website/**" + - "!content/website/**" jobs: gather_content: From 4a5244bac7126b79e6ca4b93b64fba65e83546de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Rivera=20Toro?= Date: Thu, 28 Mar 2024 12:10:53 -0400 Subject: [PATCH 10/12] Exit workflow if files are not found --- .github/workflows/news-seed-lpb.yml | 8 +++++++- .github/workflows/release-notes-seed-lpb.yaml | 13 +++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.github/workflows/news-seed-lpb.yml b/.github/workflows/news-seed-lpb.yml index 296cc114..358b7577 100644 --- a/.github/workflows/news-seed-lpb.yml +++ b/.github/workflows/news-seed-lpb.yml @@ -4,7 +4,7 @@ on: inputs: environment: description: "What environment are you seeding?" - required: true + required: false type: environment jobs: @@ -21,6 +21,12 @@ jobs: find ./content/website -type f > seed-files.txt echo "All files to upload:" cat seed-files.txt + - name: Check if files were found + run: | + if [ ! -s "seed-files.txt" ]; then + echo "No files found!" + exit 1 + fi - name: Save changed files list uses: actions/upload-artifact@v1 with: diff --git a/.github/workflows/release-notes-seed-lpb.yaml b/.github/workflows/release-notes-seed-lpb.yaml index 1cdafa06..3a1c4e13 100644 --- a/.github/workflows/release-notes-seed-lpb.yaml +++ b/.github/workflows/release-notes-seed-lpb.yaml @@ -4,7 +4,7 @@ on: inputs: environment: description: "What environment are you seeding?" - required: true + required: false type: environment jobs: @@ -12,11 +12,6 @@ jobs: name: Gather all content runs-on: ubuntu-latest steps: - - name: Fail if branch is not main - if: github.ref != 'refs/heads/main' - run: | - echo "This workflow should not be triggered with workflow_dispatch on a branch other than main" - exit 1 - name: Checkout uses: actions/checkout@v2 with: @@ -26,6 +21,12 @@ jobs: find ./content -type f -not -path "./content/website/*" > seed-files.txt echo "All files to upload:" cat seed-files.txt + - name: Check if files were found + run: | + if [ ! -s "seed-files.txt" ]; then + echo "No files found!" + exit 1 + fi - name: Save changed files list uses: actions/upload-artifact@v1 with: From d6c3319f09bcab7263a2e7e0c6b2ed024048c3ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Rivera=20Toro?= Date: Fri, 29 Mar 2024 08:09:50 -0400 Subject: [PATCH 11/12] Update workflows --- ...-seed-lpb.yml => full-seeding-of-lpb.yaml} | 42 +++- .github/workflows/release-notes-post-lpb.yaml | 191 ------------------ .github/workflows/release-notes-seed-lpb.yaml | 136 ------------- .../{news-post-lpb.yml => send-to-lpb.yaml} | 71 +++---- 4 files changed, 66 insertions(+), 374 deletions(-) rename .github/workflows/{news-seed-lpb.yml => full-seeding-of-lpb.yaml} (76%) delete mode 100644 .github/workflows/release-notes-post-lpb.yaml delete mode 100644 .github/workflows/release-notes-seed-lpb.yaml rename .github/workflows/{news-post-lpb.yml => send-to-lpb.yaml} (79%) diff --git a/.github/workflows/news-seed-lpb.yml b/.github/workflows/full-seeding-of-lpb.yaml similarity index 76% rename from .github/workflows/news-seed-lpb.yml rename to .github/workflows/full-seeding-of-lpb.yaml index 358b7577..8c1eb647 100644 --- a/.github/workflows/news-seed-lpb.yml +++ b/.github/workflows/full-seeding-of-lpb.yaml @@ -1,10 +1,10 @@ -name: Seed all news to Lighthouse Platform Backend (LPB) +name: Seed all release notes to Lighthouse Platform Backend (LPB) on: workflow_dispatch: inputs: environment: description: "What environment are you seeding?" - required: false + required: true type: environment jobs: @@ -18,7 +18,7 @@ jobs: fetch-depth: 0 - name: Find files and artifact them run: | - find ./content/website -type f > seed-files.txt + find ./content -type f > seed-files.txt echo "All files to upload:" cat seed-files.txt - name: Check if files were found @@ -70,9 +70,23 @@ jobs: 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/ | grep -v 'content/website/'`; 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 $BEARER_TOKEN" + --data "{\"date\":\"$DATE_STRING\",\"content\":\"base64:$CONTENT_STRING\"}" + https://$LPB_HOST/internal/platform-backend/v0/providers/$TARGET_API/release-notes; + sleep 1; + done; 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*//'`; + DATE_STRING=`echo $n | sed -E 's/([A-Za-z]+)-([0-9]{4}).*/\1 \2/'`; TITLE_STRING=`cat $n | 's/^.*title:\s*//'`; TARGET_NEWS_CATEGORY=`echo $n | sed -E 's/.*\/([a-z\-]{1,})\/.*/\1/' | sed 's/^./\U&/;s/-/ /g'`; SOURCE_STRING=`cat $n | 's/^.*source:\s*//'`; @@ -87,7 +101,7 @@ jobs: 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*//'`; + DATE_STRING=`echo $n | sed -E 's/([A-Za-z]+)-([0-9]{4}).*/\1 \2/'`; TITLE_STRING=`cat $n | 's/^.*title:\s*//'`; TARGET_NEWS_CATEGORY=`echo $n | sed -E 's/.*\/([a-z\-]{1,})\/.*/\1/' | sed 's/^./\U&/;s/-/ /g'`; URL_STRING=`cat $n | 's/^.*url:\s*//'`; @@ -137,9 +151,23 @@ jobs: 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/ | grep -v 'content/website/'`; 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 $BEARER_TOKEN" + --data "{\"date\":\"$DATE_STRING\",\"content\":\"base64:$CONTENT_STRING\"}" + https://$LPB_HOST/internal/platform-backend/v0/providers/$TARGET_API/release-notes; + sleep 1; + done; 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*//'`; + DATE_STRING=`echo $n | sed -E 's/([A-Za-z]+)-([0-9]{4}).*/\1 \2/'`; TITLE_STRING=`cat $n | 's/^.*title:\s*//'`; TARGET_NEWS_CATEGORY=`echo $n | sed -E 's/.*\/([a-z\-]{1,})\/.*/\1/' | sed 's/^./\U&/;s/-/ /g'`; SOURCE_STRING=`cat $n | 's/^.*source:\s*//'`; @@ -154,7 +182,7 @@ jobs: 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*//'`; + DATE_STRING=`echo $n | sed -E 's/([A-Za-z]+)-([0-9]{4}).*/\1 \2/'`; TITLE_STRING=`cat $n | 's/^.*title:\s*//'`; TARGET_NEWS_CATEGORY=`echo $n | sed -E 's/.*\/([a-z\-]{1,})\/.*/\1/' | sed 's/^./\U&/;s/-/ /g'`; URL_STRING=`cat $n | 's/^.*url:\s*//'`; diff --git a/.github/workflows/release-notes-post-lpb.yaml b/.github/workflows/release-notes-post-lpb.yaml deleted file mode 100644 index f8a5ce12..00000000 --- a/.github/workflows/release-notes-post-lpb.yaml +++ /dev/null @@ -1,191 +0,0 @@ -name: Post release notes to Lighthouse Platform Backend (LPB) -on: - pull_request: - types: - - opened - - synchronize - - reopened - - closed - branches: [main] - paths: - - "content/**" - - "!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: - - name: Fail if branch is not main - if: github.ref != 'refs/heads/main' - run: | - echo "This workflow should not be triggered with workflow_dispatch on a branch other than main" - exit 1 - - 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/get-changed-files@v2.2.0 - 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/`; 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@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/release-notes/).' - }) - - 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/`; 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@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/release-notes/).' - }) diff --git a/.github/workflows/release-notes-seed-lpb.yaml b/.github/workflows/release-notes-seed-lpb.yaml deleted file mode 100644 index 3a1c4e13..00000000 --- a/.github/workflows/release-notes-seed-lpb.yaml +++ /dev/null @@ -1,136 +0,0 @@ -name: Seed all release notes to Lighthouse Platform Backend (LPB) -on: - workflow_dispatch: - inputs: - environment: - description: "What environment are you seeding?" - required: false - 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 -type f -not -path "./content/website/*" > seed-files.txt - echo "All files to upload:" - cat seed-files.txt - - name: Check if files were found - run: | - if [ ! -s "seed-files.txt" ]; then - echo "No files found!" - exit 1 - fi - - 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/`; 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 $BEARER_TOKEN" - --data "{\"date\":\"$DATE_STRING\",\"content\":\"base64:$CONTENT_STRING\"}" - https://$LPB_HOST/internal/platform-backend/v0/providers/$TARGET_API/release-notes; - sleep 1; - 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/`; 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 $BEARER_TOKEN" - --data "{\"date\":\"$DATE_STRING\",\"content\":\"base64:$CONTENT_STRING\"}" - https://$LPB_HOST/internal/platform-backend/v0/providers/$TARGET_API/release-notes; - sleep 1; - done; diff --git a/.github/workflows/news-post-lpb.yml b/.github/workflows/send-to-lpb.yaml similarity index 79% rename from .github/workflows/news-post-lpb.yml rename to .github/workflows/send-to-lpb.yaml index d79eb199..ce466411 100644 --- a/.github/workflows/news-post-lpb.yml +++ b/.github/workflows/send-to-lpb.yaml @@ -1,4 +1,4 @@ -name: Post news to Lighthouse Platform Backend (LPB) +name: Post release notes and news to Lighthouse Platform Backend (LPB) on: pull_request: types: @@ -7,8 +7,6 @@ on: - reopened - closed branches: [main] - paths: - - "content/website/**" jobs: gather_content: @@ -33,8 +31,6 @@ jobs: fetch-depth: 0 - id: pr_files uses: Ana06/get-changed-files@v2.2.0 - with: - filter: "content/website/**" - id: upload_content name: Find files and send them continue-on-error: true @@ -92,9 +88,22 @@ jobs: env: LPB_HOST: "dev-api.va.gov" run: + for n in `cat changed-files/changed-files.txt | grep content/ | grep -v 'content/website/'`; 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; 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*//'`; + DATE_STRING=`echo $n | sed -E 's/([A-Za-z]+)-([0-9]{4}).*/\1 \2/'`; TITLE_STRING=`cat $n | 's/^.*title:\s*//'`; TARGET_NEWS_CATEGORY=`echo $n | sed -E 's/.*\/([a-z\-]{1,})\/.*/\1/' | sed 's/^./\U&/;s/-/ /g'`; SOURCE_STRING=`cat $n | 's/^.*source:\s*//'`; @@ -109,7 +118,7 @@ jobs: 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*//'`; + DATE_STRING=`echo $n | sed -E 's/([A-Za-z]+)-([0-9]{4}).*/\1 \2/'`; TITLE_STRING=`cat $n | 's/^.*title:\s*//'`; TARGET_NEWS_CATEGORY=`echo $n | sed -E 's/.*\/([a-z\-]{1,})\/.*/\1/' | sed 's/^./\U&/;s/-/ /g'`; URL_STRING=`cat $n | 's/^.*url:\s*//'`; @@ -121,27 +130,6 @@ jobs: --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] @@ -178,9 +166,22 @@ jobs: env: LPB_HOST: "api.va.gov" run: + for n in `cat changed-files/changed-files.txt | grep content/ | grep -v 'content/website/'`; 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; 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*//'`; + DATE_STRING=`echo $n | sed -E 's/([A-Za-z]+)-([0-9]{4}).*/\1 \2/'`; TITLE_STRING=`cat $n | 's/^.*title:\s*//'`; TARGET_NEWS_CATEGORY=`echo $n | sed -E 's/.*\/([a-z\-]{1,})\/.*/\1/' | sed 's/^./\U&/;s/-/ /g'`; SOURCE_STRING=`cat $n | 's/^.*source:\s*//'`; @@ -195,7 +196,7 @@ jobs: 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*//'`; + DATE_STRING=`echo $n | sed -E 's/([A-Za-z]+)-([0-9]{4}).*/\1 \2/'`; TITLE_STRING=`cat $n | 's/^.*title:\s*//'`; TARGET_NEWS_CATEGORY=`echo $n | sed -E 's/.*\/([a-z\-]{1,})\/.*/\1/' | sed 's/^./\U&/;s/-/ /g'`; URL_STRING=`cat $n | 's/^.*url:\s*//'`; @@ -207,13 +208,3 @@ jobs: --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).' - }) From 92ca075ab001584b7ec62be57a4c5be9ec1d3e8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Rivera=20Toro?= Date: Fri, 29 Mar 2024 08:10:37 -0400 Subject: [PATCH 12/12] Remove step --- .github/workflows/full-seeding-of-lpb.yaml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/full-seeding-of-lpb.yaml b/.github/workflows/full-seeding-of-lpb.yaml index 8c1eb647..2f6fba45 100644 --- a/.github/workflows/full-seeding-of-lpb.yaml +++ b/.github/workflows/full-seeding-of-lpb.yaml @@ -21,12 +21,6 @@ jobs: find ./content -type f > seed-files.txt echo "All files to upload:" cat seed-files.txt - - name: Check if files were found - run: | - if [ ! -s "seed-files.txt" ]; then - echo "No files found!" - exit 1 - fi - name: Save changed files list uses: actions/upload-artifact@v1 with: