diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index d4dd8b8d..1089b246 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -1,4 +1,4 @@ -name: Build and Deploy to S3 +name: Build and Deploy on: push: @@ -6,10 +6,8 @@ on: - main jobs: - build_and_deploy: + build_artifact: runs-on: ubuntu-latest - environment: dev - steps: - name: Checkout code uses: actions/checkout@v2 @@ -24,6 +22,61 @@ jobs: - name: Build run: yarn build + + - name: Archive build + uses: actions/upload-artifact@v3 + with: + name: yarn-${{ github.sha }} + path: build + + deploy_dev: + needs: build_artifact + runs-on: ubuntu-latest + environment: dev + steps: + - name: Download artifact + uses: actions/download-artifact@v3 + with: + name: yarn-${{ github.sha }} + + - 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 # Replace with your AWS region + + - name: Sync to S3 + run: aws s3 sync build/ s3://${{ vars.S3_BUCKET }} --size-only --delete + + - name: Invalidate CF cache + run: | + INVAL_ID=$(aws cloudfront create-invalidation --distribution-id ${{ vars.CF_DISTRO }} --paths "/*" | jq -r .Invalidation.Id ) + aws cloudfront wait invalidation-completed --distribution-id ${{ vars.CF_DISTRO }} --id $INVAL_ID + + - name: Setup Algolia Config + id: algolia_config + run: | + sed -i 's//${{ vars.ALGOLIA_INDEX }}/g' algolia.json + sed -i 's//${{ vars.FQDN }}/g' algolia.json + echo "::set-output name=config::$(cat algolia.json | jq -r tostring)" + + - name: Run Algolia Reindex + uses: signcl/docsearch-scraper-action@master + env: + APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID }} + API_KEY: ${{ secrets.ALGOLIA_API_KEY }} + CONFIG: ${{ steps.algolia_config.outputs.config }} + + deploy_stg: + needs: deploy_dev + runs-on: ubuntu-latest + environment: stg + steps: + - name: Download artifact + uses: actions/download-artifact@v3 + with: + name: yarn-${{ github.sha }} - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v1 @@ -33,7 +86,7 @@ jobs: aws-region: us-east-1 # Replace with your AWS region - name: Sync to S3 - run: aws s3 sync build/ s3://device42-docs-website-content-dev --size-only --delete + run: aws s3 sync build/ s3://${{ vars.S3_BUCKET }} --size-only --delete - name: Invalidate CF cache run: | diff --git a/.github/workflows/test-build.yml b/.github/workflows/test-build.yml new file mode 100644 index 00000000..21781e0a --- /dev/null +++ b/.github/workflows/test-build.yml @@ -0,0 +1,26 @@ +name: PR build test + +on: + pull_request: + branches: + - main + +jobs: + test_build: + name: Test build + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Use Node.js + uses: actions/setup-node@v2 + with: + node-version: '16.14' + + - name: Install Dependencies + run: yarn + + - name: Build + run: yarn build