diff --git a/.github/workflows/deploy-sandbox.yaml b/.github/workflows/deploy-sandbox.yaml index cbabebec5..a08f9b7c8 100644 --- a/.github/workflows/deploy-sandbox.yaml +++ b/.github/workflows/deploy-sandbox.yaml @@ -8,28 +8,30 @@ on: paths-ignore: - 'docs/**' - branches: - - 'ik/**' - - 'sspj/**' - - 'lmm/**' - - 'nmb/**' - - 'mr/**' - jobs: + variables: + outputs: + environment: ${{ steps.var.outputs.environment}} + runs-on: "ubuntu-latest" + steps: + - name: Setting global variables + uses: actions/github-script@v6 + id: var + with: + script: | + core.setOutput('environment', '${{ github.head_ref }}'.split("/")[0]); deploy: + if: | + ${{startsWith(github.head_ref, 'ik/') + || startsWith(github.head_ref, 'sspj/') + || startsWith(github.head_ref, 'mr/') + || startsWith(github.head_ref, 'nmb/') + || startsWith(github.head_ref, 'lmm/') + }} runs-on: ubuntu-latest + needs: [variables] steps: - uses: actions/checkout@v3 - - name: Split branch name - env: - BRANCH: ${{ github.ref_name }} - id: split - run: echo "::set-output name=fragment::${BRANCH##*/}" - - name: Set secrets - id: secret - run: | - echo "::set-output name=cf_username::CF_${{ steps.split.outputs.fragment }}_USERNAME" - echo "::set-output name=cf_password::CF_${{ steps.split.outputs.fragment }}_PASSWORD" - name: Compile USWDS assets working-directory: ./src run: | @@ -43,9 +45,28 @@ jobs: uses: 18f/cg-deploy-action@main env: DEPLOY_NOW: thanks + ENVIRONMENT: ${{ needs.variables.outputs.environment }} + CF_USERNAME: CF_${{ needs.variables.outputs.environment }}_USERNAME + CF_PASSWORD: CF_${{ needs.variables.outputs.environment }}_PASSWORD with: - cf_username: ${{ secrets[steps.secret.outputs.cf_username] }} - cf_password: ${{ secrets[steps.secret.outputs.cf_password] }} + cf_username: ${{ secrets[env.CF_USERNAME] }} + cf_password: ${{ secrets[env.CF_PASSWORD] }} cf_org: cisa-getgov-prototyping - cf_space: ${{ steps.split.outputs.fragment }} - push_arguments: "-f ops/manifests/manifest-${{ steps.split.outputs.fragment }}.yaml" \ No newline at end of file + cf_space: ${{ env.ENVIRONMENT }} + push_arguments: "-f ops/manifests/manifest-${{ env.ENVIRONMENT }}.yaml" + comment: + runs-on: ubuntu-latest + needs: [variables, deploy] + steps: + - uses: actions/github-script@v6 + env: + ENVIRONMENT: ${{ needs.variables.outputs.environment }} + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: '🥳 Successfully deployed to developer sandbox **[${{ env.ENVIRONMENT }}](https://getgov-${{ env.ENVIRONMENT }}.app.cloud.gov/)**.' + }) \ No newline at end of file diff --git a/ops/scripts/create_dev_sandbox.sh b/ops/scripts/create_dev_sandbox.sh index c64e793fe..df10d8d90 100755 --- a/ops/scripts/create_dev_sandbox.sh +++ b/ops/scripts/create_dev_sandbox.sh @@ -113,8 +113,8 @@ sed -i '' '/ - stable/ {a\ - '"$1"' }' .github/workflows/migrate.yaml -sed -i '' '/ branches:/ {a\ - - '"'$1/**'"' +sed -i '' '/${{startsWith(github.head_ref, / {a\ + || startsWith(github.head_ref, '"'$1'"') }' .github/workflows/deploy-sandbox.yaml echo "Creating space deployer for Github deploys..." diff --git a/ops/scripts/destroy_dev_sandbox.sh b/ops/scripts/destroy_dev_sandbox.sh index 733476c2c..47a7f26d8 100755 --- a/ops/scripts/destroy_dev_sandbox.sh +++ b/ops/scripts/destroy_dev_sandbox.sh @@ -49,7 +49,6 @@ rm ops/manifests/manifest-$1.yaml sed -i '' "/getgov-$1.app.cloud.gov/d" src/registrar/config/settings.py sed -i '' "/- $1/d" .github/workflows/reset-db.yaml sed -i '' "/- $1/d" .github/workflows/migrate.yaml -sed -i '' "/- $1/d" .github/workflows/deploy-sandbox.yaml echo "Cleaning up services, applications, and the Cloud.gov space for $1..." cf delete getgov-$1