From 651968ca9cb78d3274469e45782a2761cce8187e Mon Sep 17 00:00:00 2001 From: Joseph Flinn <58369717+joseph-flinn@users.noreply.github.com> Date: Fri, 27 Jan 2023 13:40:50 -0800 Subject: [PATCH] Support deploying to more non-prod environments (#4585) * Update the QA deploy workflow to deploy to multiple non-prod environments * Fix linter issues * Update with testing code if run with QA * Fix bash typo * revert name * Fix name * Adding some logging * Fix environment branch typo * Add QA configuration and renable * Rename workflow file * Update .github/workflows/deploy-non-prod-web.yml Switch config logic to a more extensible one. Co-authored-by: mimartin12 <77340197+mimartin12@users.noreply.github.com> * Fix a typo * Add the original workflow in for QA for no disruptions * Add line --------- Co-authored-by: mimartin12 <77340197+mimartin12@users.noreply.github.com> --- .github/workflows/deploy-non-prod-web.yml | 124 ++++++++++++++++++++++ .github/workflows/release-qa-web.yml | 2 +- 2 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/deploy-non-prod-web.yml diff --git a/.github/workflows/deploy-non-prod-web.yml b/.github/workflows/deploy-non-prod-web.yml new file mode 100644 index 0000000000..cc9d7c8e5a --- /dev/null +++ b/.github/workflows/deploy-non-prod-web.yml @@ -0,0 +1,124 @@ +--- +name: Deploy Web - Non-Prod +run-name: Deploy Web ${{ inputs.environment }} + +on: + workflow_dispatch: + inputs: + environment: + description: 'Environment' + required: true + default: 'QA' + type: choice + options: + - QA + - POC + + +jobs: + setup: + name: Setup + runs-on: ubuntu-20.04 + outputs: + environment: ${{ steps.config.outputs.environment }} + environment-url: ${{ steps.config.outputs.environment-url }} + environment-name: ${{ steps.config.outputs.environment-name }} + environment-branch: ${{ steps.config.outputs.environment-branch }} + environment-artifact: ${{ steps.config.outputs.environment-artifact }} + steps: + - name: Configure + id: config + run: | + ENV_NAME_LOWER=$(echo "${{ inputs.environment }}" | awk '{print tolower($0)}') + echo "configuring the Web deploy for ${{ inputs.environment }}" + echo "environment=${{ inputs.environment }}" >> $GITHUB_OUTPUT + echo "environment-url=http://vault.$ENV_NAME_LOWER.bitwarden.pw" >> $GITHUB_OUTPUT + echo "environment-name=Web Vault - ${{ inputs.environment }}" >> $GITHUB_OUTPUT + echo "environment-branch=cf-pages-$ENV_NAME_LOWER" >> $GITHUB_OUTPUT + echo "environment-artifact=web-*-cloud-${{ inputs.environment }}.zip" >> $GITHUB_OUTPUT + + + cfpages-deploy: + name: Deploy Web Vault to ${{ inputs.environment }} CloudFlare Pages branch + needs: setup + runs-on: ubuntu-20.04 + env: + _ENVIRONMENT: ${{ needs.setup.outputs.environment }} + _ENVIRONMENT_URL: ${{ needs.setup.outputs.environment-url }} + _ENVIRONMENT_NAME: ${{ needs.setup.outputs.environment-name }} + _ENVIRONMENT_BRANCH: ${{ needs.setup.outputs.environment-branch }} + _ENVIRONMENT_ARTIFACT: ${{ needs.setup.outputs.environment-artifact }} + steps: + - name: Create GitHub deployment + uses: chrnorm/deployment-action@1b599fe41a0ef1f95191e7f2eec4743f2d7dfc48 + id: deployment + with: + token: '${{ secrets.GITHUB_TOKEN }}' + initial-status: 'in_progress' + environment-url: ${{ env._ENVIRONMENT_URL }} + environment: ${{ env._ENVIRONMENT_NAME }} + description: 'Deployment from branch ${{ github.ref_name }}' + + - name: Checkout Repo + uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2 + + - name: Download latest cloud asset + uses: bitwarden/gh-actions/download-artifacts@850faad0cf6c02a8c0dc46eddde2363fbd6c373a + with: + workflow: build-web.yml + path: apps/web + workflow_conclusion: success + branch: ${{ github.ref_name }} + artifacts: ${{ env._ENVIRONMENT_ARTIFACT }} + + - name: Unzip cloud asset + working-directory: apps/web + run: unzip ${{ env._ENVIRONMENT_ARTIFACT }} + + - name: Checkout Repo + uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2 + with: + ref: ${{ env._ENVIRONMENT_BRANCH }} + path: deployment + + - name: Setup git config + run: | + git config --global user.name "GitHub Action Bot" + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" + git config --global url."https://github.com/".insteadOf ssh://git@github.com/ + git config --global url."https://".insteadOf ssh:// + + - name: Deploy CloudFlare Pages + run: | + rm -rf ./* + cp -R ../apps/web/build/* . + working-directory: deployment + + - name: Push new ver to ${{ env._ENVIRONMENT_BRANCH }} + run: | + if [ -n "$(git status --porcelain)" ]; then + git add . + git commit -m "Deploy ${{ github.ref_name }} to ${{ env._ENVIRONMENT }} Cloudflare pages" + git push -u origin ${{ env._ENVIRONMENT_BRANCH }} + else + echo "No changes to commit!"; + fi + working-directory: deployment + + - name: Update deployment status to Success + if: ${{ success() }} + uses: chrnorm/deployment-status@07b3930847f65e71c9c6802ff5a402f6dfb46b86 + with: + token: '${{ secrets.GITHUB_TOKEN }}' + environment-url: ${{ env._ENVIRONMENT_URL }} + state: 'success' + deployment-id: ${{ steps.deployment.outputs.deployment_id }} + + - name: Update deployment status to Failure + if: ${{ failure() }} + uses: chrnorm/deployment-status@07b3930847f65e71c9c6802ff5a402f6dfb46b86 + with: + token: '${{ secrets.GITHUB_TOKEN }}' + environment-url: ${{ env._ENVIRONMENT_URL }} + state: 'failure' + deployment-id: ${{ steps.deployment.outputs.deployment_id }} diff --git a/.github/workflows/release-qa-web.yml b/.github/workflows/release-qa-web.yml index b7abb35ead..dea34a2e6f 100644 --- a/.github/workflows/release-qa-web.yml +++ b/.github/workflows/release-qa-web.yml @@ -30,7 +30,7 @@ jobs: workflow_conclusion: success branch: ${{ github.ref_name }} artifacts: web-*-cloud-QA.zip - + - name: Unzip cloud asset working-directory: apps/web run: unzip web-*-cloud-QA.zip