Pr env improvements #29
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This action will create the azure resources, github secret, github environment, and deploy the app when a PR once is opened. | |
name: Deploy PR | |
on: | |
pull_request: | |
types: [opened, reopened, synchronize] | |
branches: master | |
env: | |
AZURE_WEBAPP_NAME: gccollab-dev-pr-${{ github.event.number }} | |
AZURE_WEBAPP_PACKAGE_PATH: './dist/gccollab-frontend' | |
NODE_VERSION: '16.14.2' | |
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} | |
LOCATION: canadaeast | |
SECRET_NAME: PR_${{ github.event.number }} | |
jobs: | |
setup: | |
name: Deploy Bicep | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@master | |
- uses: azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: Create Resources | |
uses: azure/CLI@v1 | |
with: | |
azcliversion: 2.30.0 | |
inlineScript: | | |
if [[ ${{ github.event.action }} != "synchronize" ]]; then | |
az deployment sub create -l ${{ env.LOCATION }} -f ./.bicep/pr-instance-setup.bicep --parameters prNumber=${{ github.event.number }} location=${{ env.LOCATION }} | |
else | |
echo "This has already been deployed." | |
fi | |
store: | |
name: Store Publishing Profile | |
runs-on: ubuntu-latest | |
needs: setup | |
steps: | |
- name: Azure Login | |
uses: azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: Get Publishing Profile | |
id: get-publishing-profile | |
run: | | |
if [[ ${{ github.event.action }} != "synchronize" ]]; then | |
profile=$(az webapp deployment list-publishing-profiles --resource-group ${{ env.AZURE_WEBAPP_NAME }} --name ${{ env.AZURE_WEBAPP_NAME }} --xml | sed -e 's|\"<|<|g' | sed -e 's|>\"|>|g' | sed -e 's|\\"|"|g' | sed -e 's|\\\\|\\|g') | |
echo "::set-output name=profile::$profile" | |
else | |
echo "Publishing profile has already been retrieved." | |
fi | |
- name: GitHub Auth Login | |
shell: bash | |
run: gh auth login --with-token <<< ${{ env.ACCESS_TOKEN }} | |
- uses: actions/checkout@master | |
- name: Create Secret | |
run: | | |
if [[ ${{ github.event.action }} != "synchronize" ]]; then | |
escaped_profile=$(printf "%q" "${{ env.PROFILE }}") | |
gh secret set "${{ env.SECRET_NAME }}" --body "$escaped_profile" | |
else | |
echo "Secret has already been stored." | |
fi | |
env: | |
PROFILE: ${{ steps.get-publishing-profile.outputs.profile }} | |
create-environment: | |
name: Create Environment | |
runs-on: ubuntu-latest | |
needs: [setup, store] | |
steps: | |
- name: Create Environment | |
shell: bash | |
run: | | |
if [[ ${{ github.event.action }} != "synchronize" ]]; then | |
curl -X POST "https://api.github.com/repos/gctools-outilsgc/gccollab-frontend/environments" \ | |
-H "Authorization: token ${{ env.ACCESS_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
-d "{\"name\":\"PR ${{ github.event.number }}\"}" | |
else | |
echo "Environment has already been created." | |
fi | |
build-test-and-deploy: | |
name: Build, Test and Deploy | |
runs-on: windows-latest | |
needs: [setup, store, create-environment] | |
environment: | |
name: PR ${{ github.event.number }} | |
url: https://${{ env.AZURE_WEBAPP_NAME }}.azurewebsites.net/ | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Use Node.js ${{ env.NODE_VERSION }} | |
uses: actions/setup-node@v1 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- name: Install | |
run: npm install | |
- name: Build | |
run: npm run build-pr --if-present | |
- name: Test | |
run: npm run test --if-present -- --watch=false --browsers=ChromeHeadless | |
- name: Azure Login | |
uses: azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: 'Deploy to Azure WebApp' | |
uses: azure/webapps-deploy@v1 | |
with: | |
app-name: ${{ env.AZURE_WEBAPP_NAME }} | |
publish-profile: ${{ secrets[env.SECRET_NAME] }} | |
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} |