From 63c47f4d9219dc10e8c95a29025b981e0a691a41 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 20 Dec 2022 14:57:37 -0500 Subject: [PATCH] Revert "DX-3003 DX-2971 Workflow Change to One S3 Bucket and CF Test Cleanup" --- .github/workflows/listener.yml | 2 +- .github/workflows/pr-closed-delete-bucket.yml | 36 +++ .../pr-closed-delete-staging-site.yml | 120 --------- .github/workflows/pr-publish-docsite.yml | 238 ++++++++++++++++-- site/cypress/e2e/tests/docs.cy.js | 14 +- site/cypress/e2e/tests/docs_sidebar.cy.js | 2 +- .../e2e/tests/migration_guides_sidebar.cy.js | 2 +- site/cypress/e2e/tests/navbar.cy.js | 2 +- site/cypress/e2e/tests/search.cy.js | 6 +- site/cypress/utils/utils.js | 2 +- site/docusaurus.config.js | 4 +- site/migration-guides/intro.mdx | 2 +- site/src/components/SplashPage.js | 6 +- site/src/pages/apis/global/index.js | 8 +- site/src/pages/apis/index.js | 20 +- site/src/pages/docs/index.js | 14 +- site/src/pages/sdks/index.js | 12 +- 17 files changed, 300 insertions(+), 190 deletions(-) create mode 100644 .github/workflows/pr-closed-delete-bucket.yml delete mode 100644 .github/workflows/pr-closed-delete-staging-site.yml diff --git a/.github/workflows/listener.yml b/.github/workflows/listener.yml index 0565176ce..820b08e5d 100644 --- a/.github/workflows/listener.yml +++ b/.github/workflows/listener.yml @@ -51,7 +51,7 @@ jobs: issue_number: ${{ github.event.client_payload.prNumber }}, owner: 'Bandwidth', repo: '${{ github.event.client_payload.originRepo }}', - body: 'Preview site: http://{{ env.BRANCH_NAME }}.staging-dev.bandwidth.com/\nPlease note that it may take a couple minutes for your preview site to become available.\n\nSee the corresponding PR opened on the docsite repository (no action required):\nhttps://github.com/Bandwidth/api-docs/pull/${{ env.PR_NUMBER }}' + body: 'Preview site: http://bw-api-docs-${{ env.BRANCH_NAME }}.s3-website-us-east-1.amazonaws.com/\nPlease note that it may take a couple minutes for your preview site to become available.\n\nSee the corresponding PR opened on the docsite repository (no action required):\nhttps://github.com/Bandwidth/api-docs/pull/${{ env.PR_NUMBER }}' }) merge: diff --git a/.github/workflows/pr-closed-delete-bucket.yml b/.github/workflows/pr-closed-delete-bucket.yml new file mode 100644 index 000000000..2ba193a7f --- /dev/null +++ b/.github/workflows/pr-closed-delete-bucket.yml @@ -0,0 +1,36 @@ +# Deletes the staging docsite bucket on PR closed + +name: PR Closed Delete Bucket + +on: + pull_request: + types: [closed] + branches: + - 'main' + paths: + - 'site/**' + +jobs: + delete_bucket: + name: Delete Bucket + runs-on: ubuntu-latest + steps: + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 + - name: Create Bucket Name + id: create_name + run: | + BUCKET_NAME=bw-api-docs-${GITHUB_HEAD_REF#refs/heads/} + BUCKET_NAME=$(echo "$BUCKET_NAME" | tr '[:upper:]' '[:lower:]') #convert to lowercase for AWS bucket (can't be uppercase) + BUCKET_NAME=$(echo "$BUCKET_NAME" | sed -e "s/[^a-z0-9]/-/g") #replace all remaining non alphanumerics with - + echo $BUCKET_NAME + echo "::set-output name=bucket_name::$BUCKET_NAME" + - name: Delete Bucket + run: | + aws s3 rb s3://$BUCKET_NAME --force --region us-east-1 + env: + BUCKET_NAME: ${{ steps.create_name.outputs.bucket_name }} diff --git a/.github/workflows/pr-closed-delete-staging-site.yml b/.github/workflows/pr-closed-delete-staging-site.yml deleted file mode 100644 index 0aebae69f..000000000 --- a/.github/workflows/pr-closed-delete-staging-site.yml +++ /dev/null @@ -1,120 +0,0 @@ -# Deletes the staging docsite folder in the staging bucket on a closed PR - -name: PR Closed Delete Staging Site - -on: - pull_request: - types: [closed] - branches: - - 'main' - paths: - - 'site/**' - -jobs: - cypress_cloudfront: - name: Cypress Against Cloudfront Staged Site - runs-on: ubuntu-latest - if: github.event.pull_request.merged == true - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest] - browser: [chrome] - steps: - - name: Setup Node - uses: actions/setup-node@v2 - with: - node-version: 16 - - - name: Checkout - uses: actions/checkout@v2 - - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: us-east-1 - - - name: Set Environment Variables - run: | - BRANCH_NAME=${GITHUB_HEAD_REF#refs/heads/} - BRANCH_NAME=$(echo "$BRANCH_NAME" | tr '[:upper:]' '[:lower:]') - BRANCH_NAME=$(echo "$BRANCH_NAME" | sed -e "s/[^a-z0-9]/-/g") - echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV - - - name: Create Cypress Config - run: | - cd ./site - cat >staged-cypress.config.js <> $GITHUB_ENV - - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: us-east-1 - - - name: Cleanup S3 Bucket - run: aws s3 rm s3://staging-dev-docsite/ --recursive --exclude "*" --include "${{ env.BRANCH_NAME }}/*" - - notify_for_failures: - name: Notify for Failures - needs: [cypress_cloudfront, delete_bucket_folder] - if: failure() - runs-on: ubuntu-latest - steps: - - name: Notify Slack of Failures - uses: Bandwidth/build-notify-slack-action@v1.0.0 - with: - job-status: failure - slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }} - slack-channel: ${{ secrets.SLACK_CHANNEL }} diff --git a/.github/workflows/pr-publish-docsite.yml b/.github/workflows/pr-publish-docsite.yml index 580b32d40..8e4f40c25 100644 --- a/.github/workflows/pr-publish-docsite.yml +++ b/.github/workflows/pr-publish-docsite.yml @@ -71,33 +71,148 @@ jobs: with: node-version: 16 - - name: Set Environment Variables - run: | - BRANCH_NAME=${GITHUB_HEAD_REF#refs/heads/} - BRANCH_NAME=$(echo "$BRANCH_NAME" | tr '[:upper:]' '[:lower:]') - BRANCH_NAME=$(echo "$BRANCH_NAME" | sed -e "s/[^a-z0-9]/-/g") - echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV - - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: us-east-1 - - name: Generate Static Site run: | cd site yarn install --pure-lockfile npm run build - - name: Sync Zip to Bucket + - name: Create Bucket Name + id: create_name run: | - aws s3 sync ./site/build s3://staging-dev-docsite/$BRANCH_NAME --acl public-read + BUCKET_NAME=bw-api-docs-${GITHUB_HEAD_REF#refs/heads/} + BUCKET_NAME=$(echo "$BUCKET_NAME" | tr '[:upper:]' '[:lower:]') #convert to lowercase for AWS bucket (can't be uppercase) + BUCKET_NAME=$(echo "$BUCKET_NAME" | sed -e "s/[^a-z0-9]/-/g") #replace all remaining non alphanumerics with - + echo "BUCKET_NAME=$BUCKET_NAME" >> $GITHUB_ENV - - name: Invalidate CF Cache + - name: Sync S3 Bucket + uses: Bandwidth/s3-sync-action@v1.3.0 + with: + bucket-name: ${{ env.BUCKET_NAME }} + bucket-region: us-east-1 + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + content-path: ./site/build + + - name: Create Cloudfront distribution + id: distribution run: | - aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID}} --paths "/" "/*" + cat >dist-config.json <staged-cypress.config.js <cloudfront.json + cat >distribution.json + aws cloudfront get-distribution-config --id ${{ needs.publish.outputs.id }} | \ + jq .DistributionConfig.Enabled=false > cloudfront.json + jq -r .DistributionConfig cloudfront.json > distribution.json + response=$(aws cloudfront update-distribution --id ${{ needs.publish.outputs.id }} \ + --if-match $(jq .ETag cloudfront.json -r) \ + --distribution-config file://distribution.json) + aws cloudfront wait distribution-deployed --id ${{ needs.publish.outputs.id }} + aws cloudfront delete-distribution --id ${{ needs.publish.outputs.id }} --if-match $(echo $response | jq .ETag -r) + alert_if_failure: name: Alert for failure - needs: [cypress, publish] + needs: [cypress, publish, cypress_cloudfront] if: failure() && !github.event.pull_request.draft runs-on: ubuntu-latest steps: @@ -160,5 +354,5 @@ jobs: issue_number: '${{ env.SPECS_PR_NUMBER }}', owner: 'Bandwidth', repo: 'api-specs', - body: 'http://$BUCKET_NAME.staging-dev.bandwidth.com/' + body: 'http://${{ env.BUCKET_NAME }}.s3-website-us-east-1.amazonaws.com/' }) diff --git a/site/cypress/e2e/tests/docs.cy.js b/site/cypress/e2e/tests/docs.cy.js index 73def6f21..55ec48c80 100644 --- a/site/cypress/e2e/tests/docs.cy.js +++ b/site/cypress/e2e/tests/docs.cy.js @@ -1,7 +1,7 @@ import {testTextLink, testSvgLink} from '../../utils/utils' context('Account Text Link', () => { - testTextLink('/docs/', 'Account', 'docs/account', '[data-cy="textLink"]') + testTextLink('/docs', 'Account', 'docs/account', '[data-cy="textLink"]') }) context('Account SVG Link', () => { @@ -9,7 +9,7 @@ context('Account SVG Link', () => { }) context('Numbers Text Link', () => { - testTextLink('/docs/','Numbers','docs/numbers', '[data-cy="textLink"]') + testTextLink('/docs','Numbers','docs/numbers', '[data-cy="textLink"]') }) context('Numbers SVG Link', () => { @@ -17,7 +17,7 @@ context('Numbers SVG Link', () => { }) context('Voice Text Link', () => { - testTextLink('/docs/','Voice', 'docs/voice', '[data-cy="textLink"]') + testTextLink('/docs','Voice', 'docs/voice', '[data-cy="textLink"]') }) context('Voice SVG Link', () => { @@ -25,7 +25,7 @@ context('Voice SVG Link', () => { }) context('Messaging Text Link', () => { - testTextLink('/docs/','Messaging','docs/messaging', '[data-cy="textLink"]') + testTextLink('/docs','Messaging','docs/messaging', '[data-cy="textLink"]') }) context('Messaging SVG Link', () => { @@ -33,7 +33,7 @@ context('Messaging SVG Link', () => { }) context('WebRTC Text Link', () => { - testTextLink('/docs/','WebRTC', 'docs/webrtc' ,'[data-cy="textLink"]') + testTextLink('/docs','WebRTC', 'docs/webrtc' ,'[data-cy="textLink"]') }) context('WebRTC SVG Link', () => { @@ -41,7 +41,7 @@ context('WebRTC SVG Link', () => { }) context('Multi-Factor Authentication Text Link', () => { - testTextLink('/docs/','Multi-Factor Authentication', 'docs/mfa' ,'[data-cy="textLink"]') + testTextLink('/docs','Multi-Factor Authentication', 'docs/mfa' ,'[data-cy="textLink"]') }) context('Multi-Factor Authentication SVG Link', () => { @@ -49,7 +49,7 @@ context('Multi-Factor Authentication SVG Link', () => { }) context('Emergency Text Link', () => { - testTextLink('/docs/','Emergency', 'docs/emergency' ,'[data-cy="textLink"]') + testTextLink('/docs','Emergency', 'docs/emergency' ,'[data-cy="textLink"]') }) context('Emergency SVG Link', () => { diff --git a/site/cypress/e2e/tests/docs_sidebar.cy.js b/site/cypress/e2e/tests/docs_sidebar.cy.js index d079cbf47..3b0b8c45a 100644 --- a/site/cypress/e2e/tests/docs_sidebar.cy.js +++ b/site/cypress/e2e/tests/docs_sidebar.cy.js @@ -3,7 +3,7 @@ import {testSidebar} from '../../utils/utils' context('Testing the Docs Sidebar Tabs', () => { beforeEach(() => { - cy.visit('/docs/versions/') + cy.visit('/docs/versions') }) it('Should verify that the Account Management tab and sub-tabs opens and closes properly', () => { diff --git a/site/cypress/e2e/tests/migration_guides_sidebar.cy.js b/site/cypress/e2e/tests/migration_guides_sidebar.cy.js index 66b905c0d..0c52e6b4e 100644 --- a/site/cypress/e2e/tests/migration_guides_sidebar.cy.js +++ b/site/cypress/e2e/tests/migration_guides_sidebar.cy.js @@ -3,7 +3,7 @@ import {testSidebar} from '../../utils/utils' context('Testing the Migration Guides Sidebar Tabs', () => { beforeEach(() => { - cy.visit('/migration-guides/') + cy.visit('/migration-guides') }) it('Should verify that the Python tab and subtabs opens and closes properly', () => { diff --git a/site/cypress/e2e/tests/navbar.cy.js b/site/cypress/e2e/tests/navbar.cy.js index b51e4ac4a..a45cd81b2 100644 --- a/site/cypress/e2e/tests/navbar.cy.js +++ b/site/cypress/e2e/tests/navbar.cy.js @@ -40,7 +40,7 @@ it('Should verify the external link worked', () => { context('Dev Docs Brand Logo/Link', () => { it('cy.go() - go back or forward in the browser\'s history', () => { - cy.visit('/docs/') + cy.visit('/docs') cy.get('.navbar__brand') .click() cy.location('pathname').should('include', '/') diff --git a/site/cypress/e2e/tests/search.cy.js b/site/cypress/e2e/tests/search.cy.js index 707c6f7ed..14a18a093 100644 --- a/site/cypress/e2e/tests/search.cy.js +++ b/site/cypress/e2e/tests/search.cy.js @@ -9,7 +9,7 @@ context('Algolia Search', () => { }) context('Redoc Search', () => { - redocSearchTester('/apis/messaging/', 'List') - redocSearchTester('/apis/numbers/', 'CampaignManagement') - redocSearchTester('/apis/voice/', '/calls') + redocSearchTester('/apis/messaging', 'List') + redocSearchTester('/apis/numbers', 'CampaignManagement') + redocSearchTester('/apis/voice', '/calls') }) diff --git a/site/cypress/utils/utils.js b/site/cypress/utils/utils.js index e706bcd11..05ebb4295 100644 --- a/site/cypress/utils/utils.js +++ b/site/cypress/utils/utils.js @@ -99,7 +99,7 @@ export const navTester = (path) => { export const downloadButtonTester = (path) => { it('checks the download button to verify it exists',() => { - cy.visit(`/apis/${path}/`) + cy.visit(`/apis/${path}`) cy.get('p') .contains("Download OpenAPI specification") .children('a') diff --git a/site/docusaurus.config.js b/site/docusaurus.config.js index f9a3feb89..d1a464cfd 100644 --- a/site/docusaurus.config.js +++ b/site/docusaurus.config.js @@ -28,10 +28,10 @@ module.exports = { tagline: 'Learn About Bandwidth\'s Product APIs', url: 'https://dev.bandwidth.com', baseUrl: '/', - onBrokenLinks: 'warn', + onBrokenLinks: 'throw', onBrokenMarkdownLinks: 'warn', favicon: 'img/favicon.ico', - trailingSlash: false, + trailingSlash: true, organizationName: 'bandwidth', projectName: 'api-docs', themeConfig: { diff --git a/site/migration-guides/intro.mdx b/site/migration-guides/intro.mdx index 89b25a9ab..fc2ef75fe 100644 --- a/site/migration-guides/intro.mdx +++ b/site/migration-guides/intro.mdx @@ -16,4 +16,4 @@ image: '@site/static/img/bw-icon.svg' Home of migration guides between major versions of each SDK language -* [Python](/migration-guides/python/) +* [Python](/migration-guides/python) diff --git a/site/src/components/SplashPage.js b/site/src/components/SplashPage.js index 917c28682..7637d5db3 100644 --- a/site/src/components/SplashPage.js +++ b/site/src/components/SplashPage.js @@ -6,7 +6,7 @@ const guides = { title: 'Check out our guides', text: `Explore our API guides to learn more about Bandwidth's APIs and the things you can do with us.`, linkText: 'Read the guides →', - link: '/docs/' + link: '/docs' } const guidesImage = require('@site/static/img/guides-splash.svg').default; @@ -14,7 +14,7 @@ const apis = { title: 'Dig into our API reference', text: `Use the API technical reference to get the detailed information developers need when coding. Get the nitty-gritty details about resources in our APIs.`, linkText: 'See our API reference →', - link: '/apis/' + link: '/apis' } const apisImage = require('@site/static/img/apis-splash.svg').default; @@ -22,7 +22,7 @@ const sdks = { title: 'Looking for our SDKs?', text: `We offer SDKs for several popular languages. Build your apps using our official SDKs in the language of your choice.`, linkText: 'Build with Bandwidth →', - link: '/sdks/' + link: '/sdks' } const sdksImage = require('@site/static/img/sdks-splash.svg').default; diff --git a/site/src/pages/apis/global/index.js b/site/src/pages/apis/global/index.js index 448ea589a..8d96d4606 100644 --- a/site/src/pages/apis/global/index.js +++ b/site/src/pages/apis/global/index.js @@ -7,10 +7,10 @@ import SpecVersionDropdown from '@site/src/components/SpecVersionDropdown'; export default function ApiReferencePage() { const {siteConfig} = useDocusaurusContext(); const options = [ - {title: "V1", link: "/apis/global/"}, - {title: "V2", link: "/apis/global/v2/"}, - {title: "V3", link: "/apis/global/v3/"}, - {title: "Beta", link: "/apis/global/beta/"} + {title: "V1", link: "/apis/global"}, + {title: "V2", link: "/apis/global/v2"}, + {title: "V3", link: "/apis/global/v3"}, + {title: "Beta", link: "/apis/global/beta"} ]; const version = "V1" diff --git a/site/src/pages/apis/index.js b/site/src/pages/apis/index.js index bdc217393..626a29764 100644 --- a/site/src/pages/apis/index.js +++ b/site/src/pages/apis/index.js @@ -6,53 +6,53 @@ const apiList = [ { title: 'Voice API', Svg: require('@site/static/img/api-icons/voice.svg').default, - link: '/apis/voice/' + link: '/apis/voice' }, { title: 'Phone Number Lookup API', Svg: require('@site/static/img/api-icons/phone-number-lookup.svg').default, - link: '/apis/number-lookup/' + link: '/apis/number-lookup' }, { title: 'Numbers API', Svg: require('@site/static/img/api-icons/numbers.svg').default, - link: '/apis/numbers/' + link: '/apis/numbers' }, { title: 'Multi-Factor Authentication API', Svg: require('@site/static/img/api-icons/mfa.svg').default, - link: '/apis/multifactorauth/' + link: '/apis/multifactorauth' }, { title: 'Messaging API', Svg: require('@site/static/img/api-icons/messaging.svg').default, - link: '/apis/messaging/' + link: '/apis/messaging' }, { title: 'International Messaging API', Svg: require('@site/static/img/api-icons/international-messaging.svg').default, - link: '/apis/messaging-international/' + link: '/apis/messaging-international' }, { title: 'Emergency API', Svg: require('@site/static/img/api-icons/emergency.svg').default, - link: '/apis/dash/' + link: '/apis/dash' }, { title: 'Emergency Notifications API', Svg: require('@site/static/img/api-icons/emergency-notifications.svg').default, - link: '/apis/dash-notifications/' + link: '/apis/dash-notifications' }, { title: 'WebRTC API', Svg: require('@site/static/img/api-icons/webrtc.svg').default, - link: '/apis/webrtc/' + link: '/apis/webrtc' }, { title: 'Insights API', Svg: require('@site/static/img/api-icons/insights.svg').default, - link: '/apis/insights/' + link: '/apis/insights' }, /* TODO ONEID-1304 { diff --git a/site/src/pages/docs/index.js b/site/src/pages/docs/index.js index e9b607a66..7f599d1a2 100644 --- a/site/src/pages/docs/index.js +++ b/site/src/pages/docs/index.js @@ -6,37 +6,37 @@ const productList = [ { title: 'Account', Svg: require('@site/static/img/product-icons/account.svg').default, - link: '/docs/account/' + link: '/docs/account' }, { title: 'Numbers', Svg: require('@site/static/img/product-icons/numbers.svg').default, - link: '/docs/numbers/', + link: '/docs/numbers', }, { title: 'Emergency', Svg: require('@site/static/img/product-icons/emergency.svg').default, - link: '/docs/emergency/', + link: '/docs/emergency', }, { title: 'Voice', Svg: require('@site/static/img/product-icons/voice.svg').default, - link: '/docs/voice/', + link: '/docs/voice', }, { title: 'Multi-Factor Authentication', Svg: require('@site/static/img/product-icons/mfa.svg').default, - link: '/docs/mfa/', + link: '/docs/mfa', }, { title: 'Messaging', Svg: require('@site/static/img/product-icons/messaging.svg').default, - link: '/docs/messaging/', + link: '/docs/messaging', }, { title: 'WebRTC', Svg: require('@site/static/img/product-icons/webrtc.svg').default, - link: '/docs/webrtc/', + link: '/docs/webrtc', }, // { TODO ONEID-1304 // title: 'Identity Management', diff --git a/site/src/pages/sdks/index.js b/site/src/pages/sdks/index.js index a55a220d1..4d93e35fe 100644 --- a/site/src/pages/sdks/index.js +++ b/site/src/pages/sdks/index.js @@ -6,32 +6,32 @@ const sdkList = [ { title: 'Node', Svg: require('@site/static/img/sdk-icons/node.svg').default, - link: '/sdks/node/' + link: '/sdks/node' }, { title: 'Python', Svg: require('@site/static/img/sdk-icons/python.svg').default, - link: '/sdks/python/' + link: '/sdks/python' }, { title: 'Java', Svg: require('@site/static/img/sdk-icons/java.svg').default, - link: '/sdks/java/' + link: '/sdks/java' }, { title: 'PHP', Svg: require('@site/static/img/sdk-icons/php.svg').default, - link: '/sdks/php/' + link: '/sdks/php' }, { title: 'Ruby', Svg: require('@site/static/img/sdk-icons/ruby.svg').default, - link: '/sdks/ruby/' + link: '/sdks/ruby' }, { title: 'C#', Svg: require('@site/static/img/sdk-icons/csharp.svg').default, - link: '/sdks/csharp/' + link: '/sdks/csharp' }, ];