From 9fb00bdd5e8cd53e28723e1c6db15aa67c957805 Mon Sep 17 00:00:00 2001 From: doug0102 Date: Tue, 30 Jan 2024 16:51:45 -0500 Subject: [PATCH 01/14] added synchronize to the pr deploy workflow. --- .github/workflows/deploy-pr.yml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy-pr.yml b/.github/workflows/deploy-pr.yml index 80091000..e3479b5f 100644 --- a/.github/workflows/deploy-pr.yml +++ b/.github/workflows/deploy-pr.yml @@ -4,7 +4,7 @@ name: Deploy PR on: pull_request: - types: [opened, reopened] # TODO: synchronize + types: [opened, reopened, synchronize] branches: main env: @@ -51,8 +51,12 @@ jobs: - name: Get Publishing Profile id: get-publishing-profile run: | - 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" + 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 "The publishing profile has already been retrieved." + fi - name: GitHub Auth Login shell: bash @@ -61,8 +65,12 @@ jobs: - uses: actions/checkout@v3 - name: Create Secret run: | - escaped_profile=$(printf "%q" "${{ env.PROFILE }}") - gh secret set "${{ env.SECRET_NAME }}" --body "$escaped_profile" + if [[ ${{ github.event.action }} != "synchronize" ]]; then + escaped_profile=$(printf "%q" "${{ env.PROFILE }}") + gh secret set "${{ env.SECRET_NAME }}" --body "$escaped_profile" + else + echo "The publishing profile secret has already been saved." + fi env: PROFILE: ${{ steps.get-publishing-profile.outputs.profile }} From 472fcf671ad28a74310899932531d150466dfc21 Mon Sep 17 00:00:00 2001 From: doug0102 Date: Tue, 30 Jan 2024 17:18:42 -0500 Subject: [PATCH 02/14] log the publishing profile to debug --- .github/workflows/deploy-pr.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/deploy-pr.yml b/.github/workflows/deploy-pr.yml index e3479b5f..089614cd 100644 --- a/.github/workflows/deploy-pr.yml +++ b/.github/workflows/deploy-pr.yml @@ -56,6 +56,8 @@ jobs: echo "::set-output name=profile::$profile" else echo "The publishing profile has already been retrieved." + 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 "$profile" fi - name: GitHub Auth Login From be856648f883d324e53047e6efc43bcd0c6186fe Mon Sep 17 00:00:00 2001 From: doug0102 Date: Tue, 30 Jan 2024 17:38:53 -0500 Subject: [PATCH 03/14] added app setting for web app resource to use scm webdeploy --- .bicep/pr-instance.bicep | 4 ++++ .github/workflows/deploy-pr.yml | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.bicep/pr-instance.bicep b/.bicep/pr-instance.bicep index f38922ac..99837059 100644 --- a/.bicep/pr-instance.bicep +++ b/.bicep/pr-instance.bicep @@ -37,6 +37,10 @@ resource appService 'Microsoft.Web/sites@2022-03-01' = { name: 'WEBSITE_NODE_DEFAULT_VERSION' value: '16.14.2' } + { + name: 'WEBSITE_WEBDEPLOY_USE_SCM' + value: 'true' + } ] } } diff --git a/.github/workflows/deploy-pr.yml b/.github/workflows/deploy-pr.yml index 53cc982b..e0ee4353 100644 --- a/.github/workflows/deploy-pr.yml +++ b/.github/workflows/deploy-pr.yml @@ -1,4 +1,6 @@ # This action will create the azure resources, github secret, github environment, and deploy the app when a PR once is opened. +# https://github.com/Azure/webapps-deploy/issues/28 +# https://stackoverflow.com/questions/64376240/github-action-for-azure-webapp-failed-to-fetch-credentials-from-publish-profile/64376536#64376536 name: Deploy PR @@ -56,8 +58,6 @@ jobs: echo "::set-output name=profile::$profile" else echo "The publishing profile has already been retrieved." - 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 "$profile" fi - name: GitHub Auth Login From cc5d66d463c44033a7d6cbe4dc3276eee9032cf6 Mon Sep 17 00:00:00 2001 From: doug0102 Date: Tue, 30 Jan 2024 17:57:28 -0500 Subject: [PATCH 04/14] trigger redeploy --- .github/workflows/deploy-pr.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy-pr.yml b/.github/workflows/deploy-pr.yml index e0ee4353..6e3d144d 100644 --- a/.github/workflows/deploy-pr.yml +++ b/.github/workflows/deploy-pr.yml @@ -1,6 +1,5 @@ # This action will create the azure resources, github secret, github environment, and deploy the app when a PR once is opened. # https://github.com/Azure/webapps-deploy/issues/28 -# https://stackoverflow.com/questions/64376240/github-action-for-azure-webapp-failed-to-fetch-credentials-from-publish-profile/64376536#64376536 name: Deploy PR From 600f1ad0d7951ec6a453315c1b5018f3bb2ac3af Mon Sep 17 00:00:00 2001 From: doug0102 Date: Wed, 31 Jan 2024 11:06:54 -0500 Subject: [PATCH 05/14] trigger redeploy --- .github/workflows/deploy-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-pr.yml b/.github/workflows/deploy-pr.yml index 6e3d144d..79193805 100644 --- a/.github/workflows/deploy-pr.yml +++ b/.github/workflows/deploy-pr.yml @@ -1,5 +1,5 @@ # This action will create the azure resources, github secret, github environment, and deploy the app when a PR once is opened. -# https://github.com/Azure/webapps-deploy/issues/28 +# https://github.com/Azure/webapps-deploy/issues/28 name: Deploy PR From 9614d52a8f4e9d13ffa1667f355f257f5554fb8a Mon Sep 17 00:00:00 2001 From: doug0102 Date: Wed, 31 Jan 2024 12:08:23 -0500 Subject: [PATCH 06/14] update bicep pr instance node version using the sync script --- .bicep/pr-instance.bicep | 3 ++- src/scripts/nodeSyncWorkflows.js | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.bicep/pr-instance.bicep b/.bicep/pr-instance.bicep index 99837059..cd446b46 100644 --- a/.bicep/pr-instance.bicep +++ b/.bicep/pr-instance.bicep @@ -4,6 +4,7 @@ param appName string = resourceGroup().name param location string = 'canadaeast' param siteKind string = 'windows' param sku string = 'F1' +param nodeVersion string = '18.13.0' resource appServicePlan 'Microsoft.Web/serverfarms@2021-01-01' = { name: appName @@ -35,7 +36,7 @@ resource appService 'Microsoft.Web/sites@2022-03-01' = { } { name: 'WEBSITE_NODE_DEFAULT_VERSION' - value: '16.14.2' + value: nodeVersion } { name: 'WEBSITE_WEBDEPLOY_USE_SCM' diff --git a/src/scripts/nodeSyncWorkflows.js b/src/scripts/nodeSyncWorkflows.js index 8c31af4c..92caf44c 100644 --- a/src/scripts/nodeSyncWorkflows.js +++ b/src/scripts/nodeSyncWorkflows.js @@ -10,6 +10,11 @@ const workflowFilePaths = [ '.github/workflows/code-format.yml', ]; +// The node.js version for the azure web apps being deployed +const bicepFilePaths = [ + '.bicep/pr-instance.bicep' +]; + exec('npm run ng v', (error, stdout, stderr) => { if (error) { console.error(`Error: ${error.message}`); @@ -25,11 +30,19 @@ exec('npm run ng v', (error, stdout, stderr) => { if (nodeVersion) { for (let i = 0; i < workflowFilePaths.length; i++) { - let workflowFileContent = fs.readFileSync(workflowFilePaths[i], 'utf8'); - workflowFileContent = workflowFileContent.replace(/NODE_VERSION: ['"]\d+\.\d+\.\d+['"]/, `NODE_VERSION: '${nodeVersion}'`); - fs.writeFileSync(workflowFilePaths[i], workflowFileContent); + let fileContents = fs.readFileSync(workflowFilePaths[i], 'utf8'); + fileContents = fileContents.replace(/NODE_VERSION: ['"]\d+\.\d+\.\d+['"]/, `NODE_VERSION: '${nodeVersion}'`); + fs.writeFileSync(workflowFilePaths[i], fileContents); console.log(`${workflowFilePaths[i]} updated to use Node.js version ${nodeVersion}`); } + + for (let i = 0; i < bicepFilePaths.length; i++) { + let fileContents = fs.readFileSync(bicepFilePaths[i], 'utf8'); + fileContents = fileContents.replace(/param nodeVersion string = ['"]\d+\.\d+\.\d+['"]/, `param nodeVersion string = '${nodeVersion}'`); + fs.writeFileSync(bicepFilePaths[i], fileContents); + + console.log(`${bicepFilePaths[i]} updated to use Node.js version ${nodeVersion}`); + } } }); From a84c0722e618175b416132f31816407c88fe4fdd Mon Sep 17 00:00:00 2001 From: doug0102 Date: Wed, 31 Jan 2024 15:01:14 -0500 Subject: [PATCH 07/14] remove port numbers from URLs in the PR publishing profile --- .github/workflows/deploy-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-pr.yml b/.github/workflows/deploy-pr.yml index 79193805..6ecfccb4 100644 --- a/.github/workflows/deploy-pr.yml +++ b/.github/workflows/deploy-pr.yml @@ -53,7 +53,7 @@ jobs: 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') + 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' | sed - e 's/:[0-9]+//g') echo "::set-output name=profile::$profile" else echo "The publishing profile has already been retrieved." From d94cadc08e16bd979bb8ca6d2899ee6526e5e4d3 Mon Sep 17 00:00:00 2001 From: doug0102 Date: Wed, 31 Jan 2024 15:11:52 -0500 Subject: [PATCH 08/14] minor --- .github/workflows/deploy-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-pr.yml b/.github/workflows/deploy-pr.yml index 6ecfccb4..532e9d1c 100644 --- a/.github/workflows/deploy-pr.yml +++ b/.github/workflows/deploy-pr.yml @@ -53,7 +53,7 @@ jobs: 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' | sed - e 's/:[0-9]+//g') + 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' | sed -e 's/:[0-9]+//g') echo "::set-output name=profile::$profile" else echo "The publishing profile has already been retrieved." From ff0bfe93b7a859eff7a8d48d89b90a78b8d2d290 Mon Sep 17 00:00:00 2001 From: doug0102 Date: Wed, 31 Jan 2024 15:26:25 -0500 Subject: [PATCH 09/14] fix regex for port removal --- .github/workflows/deploy-pr.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-pr.yml b/.github/workflows/deploy-pr.yml index 532e9d1c..8efcaa5e 100644 --- a/.github/workflows/deploy-pr.yml +++ b/.github/workflows/deploy-pr.yml @@ -1,4 +1,4 @@ -# This action will create the azure resources, github secret, github environment, and deploy the app when a PR once is opened. +# This action will create the azure resources, github secret, github environment, and deploy the app when a PR is opened, reopened, or synchronized. # https://github.com/Azure/webapps-deploy/issues/28 name: Deploy PR @@ -53,7 +53,7 @@ jobs: 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' | sed -e 's/:[0-9]+//g') + 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' | sed -E 's/:[0-9]+//g') echo "::set-output name=profile::$profile" else echo "The publishing profile has already been retrieved." From 8b044f91703f85f78c76b990b08e8e069aa4fe01 Mon Sep 17 00:00:00 2001 From: doug0102 Date: Wed, 31 Jan 2024 15:45:14 -0500 Subject: [PATCH 10/14] trigger synchronize redeploy --- .github/workflows/deploy-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-pr.yml b/.github/workflows/deploy-pr.yml index 8efcaa5e..5d718d65 100644 --- a/.github/workflows/deploy-pr.yml +++ b/.github/workflows/deploy-pr.yml @@ -1,5 +1,5 @@ # This action will create the azure resources, github secret, github environment, and deploy the app when a PR is opened, reopened, or synchronized. -# https://github.com/Azure/webapps-deploy/issues/28 +# https://github.com/Azure/webapps-deploy/issues/28 name: Deploy PR From 6b02fd5ddb71b3d8127529837854a5c9e8ec0fc4 Mon Sep 17 00:00:00 2001 From: doug0102 Date: Wed, 31 Jan 2024 16:57:48 -0500 Subject: [PATCH 11/14] re-retrieve and re-save publishing profile on synch --- .github/workflows/deploy-pr.yml | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/.github/workflows/deploy-pr.yml b/.github/workflows/deploy-pr.yml index 5d718d65..a61fbfa7 100644 --- a/.github/workflows/deploy-pr.yml +++ b/.github/workflows/deploy-pr.yml @@ -52,12 +52,8 @@ jobs: - 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' | sed -E 's/:[0-9]+//g') - echo "::set-output name=profile::$profile" - else - echo "The publishing profile has already been retrieved." - fi + 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' | sed -E 's/:[0-9]+//g') + echo "::set-output name=profile::$profile" - name: GitHub Auth Login shell: bash @@ -66,12 +62,8 @@ jobs: - uses: actions/checkout@v3 - 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 "The publishing profile secret has already been saved." - fi + escaped_profile=$(printf "%q" "${{ env.PROFILE }}") + gh secret set "${{ env.SECRET_NAME }}" --body "$escaped_profile" env: PROFILE: ${{ steps.get-publishing-profile.outputs.profile }} From dc4fbb7321697bbe004c6e9c91af1b2299d9d910 Mon Sep 17 00:00:00 2001 From: doug0102 Date: Thu, 1 Feb 2024 10:22:15 -0500 Subject: [PATCH 12/14] hide publishing profile output in console --- .github/workflows/deploy-pr.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-pr.yml b/.github/workflows/deploy-pr.yml index a61fbfa7..d38ebc8c 100644 --- a/.github/workflows/deploy-pr.yml +++ b/.github/workflows/deploy-pr.yml @@ -52,8 +52,8 @@ jobs: - name: Get Publishing Profile id: get-publishing-profile run: | - 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' | sed -E 's/:[0-9]+//g') - echo "::set-output name=profile::$profile" + 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' | sed -E 's/:[0-9]+//g') > /dev/null + echo "::set-output name=profile::$profile" > /dev/null - name: GitHub Auth Login shell: bash From 7b6bcd3b26cf5c2e6d213262615d06f0890f753a Mon Sep 17 00:00:00 2001 From: doug0102 Date: Thu, 1 Feb 2024 11:08:07 -0500 Subject: [PATCH 13/14] don't escape profile --- .github/workflows/deploy-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-pr.yml b/.github/workflows/deploy-pr.yml index d38ebc8c..683897cc 100644 --- a/.github/workflows/deploy-pr.yml +++ b/.github/workflows/deploy-pr.yml @@ -63,7 +63,7 @@ jobs: - name: Create Secret run: | escaped_profile=$(printf "%q" "${{ env.PROFILE }}") - gh secret set "${{ env.SECRET_NAME }}" --body "$escaped_profile" + gh secret set "${{ env.SECRET_NAME }}" --body "${{ env.PROFILE }}" env: PROFILE: ${{ steps.get-publishing-profile.outputs.profile }} From cec122c50164200e60aa4a3ac4d2d5590346c3cb Mon Sep 17 00:00:00 2001 From: doug0102 Date: Thu, 1 Feb 2024 11:22:12 -0500 Subject: [PATCH 14/14] keep port numbers in publish url --- .github/workflows/deploy-pr.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy-pr.yml b/.github/workflows/deploy-pr.yml index 683897cc..b060545b 100644 --- a/.github/workflows/deploy-pr.yml +++ b/.github/workflows/deploy-pr.yml @@ -52,7 +52,7 @@ jobs: - name: Get Publishing Profile id: get-publishing-profile run: | - 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' | sed -E 's/:[0-9]+//g') > /dev/null + 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') > /dev/null echo "::set-output name=profile::$profile" > /dev/null - name: GitHub Auth Login @@ -61,9 +61,7 @@ jobs: - uses: actions/checkout@v3 - name: Create Secret - run: | - escaped_profile=$(printf "%q" "${{ env.PROFILE }}") - gh secret set "${{ env.SECRET_NAME }}" --body "${{ env.PROFILE }}" + run: gh secret set "${{ env.SECRET_NAME }}" --body "${{ env.PROFILE }}" env: PROFILE: ${{ steps.get-publishing-profile.outputs.profile }}