From 4b8c9d9e81a709b4032322706d5df6ad5bf4b7d2 Mon Sep 17 00:00:00 2001 From: "Martin Hinshelwood nkdAgility.com" Date: Thu, 19 Sep 2024 11:17:27 +0100 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=94=A7=20(main.yml):=20add=20AzureSit?= =?UTF-8?q?esEnvironment=20variable=20and=20GitHub=20App=20token=20for=20d?= =?UTF-8?q?eployment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce the AzureSitesEnvironment variable to manage different deployment environments (e.g., preview, canary). This change allows for more flexible and environment-specific deployments. Additionally, add steps to create a GitHub App token and use it for deploying static web apps to Azure, enhancing security and automation in the deployment process. --- .github/workflows/main.yml | 40 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 214161e47..acebe9a8d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -52,7 +52,7 @@ jobs: nkdAgility_DocsBaseURL: ${{ steps.nkdagility.outputs.docs_baseURL }} nkdAgility_DocsVersionFolder: ${{ steps.nkdagility.outputs.docs_version_folder }} nkdAgility_RunRelease: ${{ steps.nkdagility.outputs.RunRelease }} - + nkdAgility_AzureSitesEnvironment: ${{ steps.nkdagility.outputs.AzureSitesEnvironment }} steps: - name: Checkout uses: actions/checkout@v2 @@ -116,6 +116,7 @@ jobs: $WingetApplicationId = "nkdagility.azure-devops-migration-tools"; $docs_deploy_folder = "./azure-devops-migration-tools/" $docs_baseURL = "/learn/azure-devops-migration-tools" + $AzureSitesEnvironment = "" $RunRelease = 'true' } "Preview" { @@ -123,6 +124,7 @@ jobs: $WingetApplicationId = "nkdagility.azure-devops-migration-tools.Preview"; $docs_deploy_folder = "./azure-devops-migration-tools/preview/"; $docs_baseURL = "/learn/azure-devops-migration-tools/preview" + $AzureSitesEnvironment = "preview"; $RunRelease = ( ('${{ inputs.ForceRelease }}' -eq 'true' ) -or ('${{ steps.filter.outputs.src }}' -eq 'true') -or ('${{ steps.filter.outputs.docs }}' -eq 'true') ) } default { @@ -130,6 +132,7 @@ jobs: $WingetApplicationId = "nkdagility.azure-devops-migration-tools.Canary"; $docs_deploy_folder = "./azure-devops-migration-tools/canary/$branchSafeName" $docs_baseURL = "/learn/azure-devops-migration-tools/canary/$branchSafeName" + $AzureSitesEnvironment = "$branchSafeName" $RunRelease = 'false' } } @@ -141,6 +144,8 @@ jobs: echo "docs_deploy_folder=$docs_deploy_folder" >> $env:GITHUB_OUTPUT Write-Output "docs_baseURL=$docs_baseURL" echo "docs_baseURL=$docs_baseURL" >> $env:GITHUB_OUTPUT + Write-Output "We are running for the $AzureSitesEnvironment AzureSitesEnvironment!" + echo "AzureSitesEnvironment=$AzureSitesEnvironment" >> $env:GITHUB_OUTPUT Write-Output "RunRelease=$RunRelease" echo "RunRelease=$RunRelease" >> $env:GITHUB_OUTPUT Write-Output "-------------------------------------------" @@ -201,6 +206,7 @@ jobs: - nkdAgility_DocsVersionFolder: ${{needs.Setup.outputs.nkdAgility_DocsVersionFolder}} - nkdAgility_DocsDeployFolder: ${{needs.Setup.outputs.nkdAgility_DocsDeployFolder}} - nkdAgility_DocsBaseURL: ${{needs.Setup.outputs.nkdAgility_DocsBaseURL}} + - nkdAgility_AzureSitesEnvironment: ${{needs.Setup.outputs.nkdAgility_AzureSitesEnvironment}} - nkdAgility_ReleaseDescriptionState: ${{needs.Setup.outputs.nkdAgility_ReleaseDescriptionState}} - nkdAgility_RunRelease: ${{needs.Setup.outputs.nkdAgility_RunRelease}} ### GitVersion @@ -553,4 +559,34 @@ jobs: uploads: | ./_site/ => ${{needs.Setup.outputs.nkdAgility_DocsDeployFolder}} # If true, any existing files in the remote upload directories are deleted. - delete: false \ No newline at end of file + delete: false + + - uses: actions/create-github-app-token@v1 + id: app-token + with: + app-id: ${{ secrets.NKDAGILITY_BOT_APP_ID }} + private-key: ${{ secrets.NKDAGILITY_BOT_CLIENTSECRET }} + + - name: Build and Deploy + uses: Azure/static-web-apps-deploy@v1 + id: azureDeploy + with: + repo_token: ${{ steps.app-token.outputs.token }} + action: 'upload' + app_location: ./_site + skip_app_build: true + skip_api_build: true + output_location: '' + deployment_environment: ${{ (needs.Setup.outputs.nkdAgility_AzureSitesEnvironment) }} + azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }} + + - name: 'Show Summery' + if: always() + shell: pwsh + id: nkdagility-summery + run: | + $markdown = @" + ## ${{needs.Setup.outputs.GitVersion_SemVer}} (${{needs.Setup.outputs.nkdAgility_Ring}}) + Docs deployed to [${{steps.azureDeploy.outputs.static_web_app_url}}](${{steps.azureDeploy.outputs.static_web_app_url}}) + "@ + echo $markdown >> $Env:GITHUB_STEP_SUMMARY From 3eab963bf31404e0f42d7db23af3911f1c6e8583 Mon Sep 17 00:00:00 2001 From: "Martin Hinshelwood nkdAgility.com" Date: Thu, 19 Sep 2024 11:39:12 +0100 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=94=A7=20(main.yml):=20add=20addition?= =?UTF-8?q?al=20Jekyll=20build=20step=20and=20upload=20artifact?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a new step to build the site with Jekyll into a different directory (`./_site2/`) and upload it as a separate artifact. This allows for parallel builds or testing different configurations without interfering with the primary build. The commented-out Jekyll build action is retained for potential future use. --- .github/workflows/main.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index acebe9a8d..60eefbc5c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -371,6 +371,17 @@ jobs: with: name: AzureDevOpsMigrationTools-Site path: ./_site/**/* + - name: Build with Jekyll 2 + # Outputs to the './_site' directory by default + run: bundle exec jekyll build --destination ./_site2/ + env: + JEKYLL_ENV: production + # - name: Build Jekyll + # uses: jerryjvl/jekyll-build-action@v1 + - uses: actions/upload-artifact@v4 + with: + name: AzureDevOpsMigrationTools-Site2 + path: ./_site2/**/* # GitHubRelease From 93a233c94c964d88b1c0fa08229327dec036cb16 Mon Sep 17 00:00:00 2001 From: "Martin Hinshelwood nkdAgility.com" Date: Thu, 19 Sep 2024 11:40:11 +0100 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=94=A7=20(main.yml):=20update=20GitHu?= =?UTF-8?q?b=20Actions=20workflow=20to=20download=20and=20deploy=20new=20a?= =?UTF-8?q?rtifact?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a step to download the AzureDevOpsMigrationTools-Site2 artifact and update the deployment path to use the new artifact. This ensures the correct version of the site is deployed, improving the deployment process and maintaining consistency with the latest build artifacts. --- .github/workflows/main.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 60eefbc5c..6343eddbc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -578,13 +578,18 @@ jobs: app-id: ${{ secrets.NKDAGILITY_BOT_APP_ID }} private-key: ${{ secrets.NKDAGILITY_BOT_CLIENTSECRET }} + - name: Download a single artifact + uses: actions/download-artifact@v4 + with: + name: AzureDevOpsMigrationTools-Site2 + path: ./_site2 - name: Build and Deploy uses: Azure/static-web-apps-deploy@v1 id: azureDeploy with: repo_token: ${{ steps.app-token.outputs.token }} action: 'upload' - app_location: ./_site + app_location: ./_site2 skip_app_build: true skip_api_build: true output_location: '' From 0c5a33438a6be9076c0fd372476f4393278c2475 Mon Sep 17 00:00:00 2001 From: "Martin Hinshelwood nkdAgility.com" Date: Thu, 19 Sep 2024 11:49:00 +0100 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=94=A7=20(main.yml):=20add=20baseurl?= =?UTF-8?q?=20parameter=20to=20Jekyll=20build=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding the `--baseurl "/"` parameter ensures that the site is built with the correct base URL, which is essential for proper linking and resource loading in the production environment. This change helps avoid issues related to incorrect paths when the site is deployed. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6343eddbc..519cdc596 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -373,7 +373,7 @@ jobs: path: ./_site/**/* - name: Build with Jekyll 2 # Outputs to the './_site' directory by default - run: bundle exec jekyll build --destination ./_site2/ + run: bundle exec jekyll build --destination ./_site2/ --baseurl "/" env: JEKYLL_ENV: production # - name: Build Jekyll From 6ce0236b2e4f5a32b21d71c92fb848d8ffb6a9b3 Mon Sep 17 00:00:00 2001 From: "Martin Hinshelwood nkdAgility.com" Date: Thu, 19 Sep 2024 11:57:20 +0100 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=94=A7=20(main.yml):=20update=20Jekyl?= =?UTF-8?q?l=20build=20command=20to=20use=20an=20empty=20baseurl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The baseurl parameter is set to an empty string to ensure that the site builds correctly without appending any base URL. This change is necessary to avoid potential issues with URL paths when deploying the site. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 519cdc596..c7b20c575 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -373,7 +373,7 @@ jobs: path: ./_site/**/* - name: Build with Jekyll 2 # Outputs to the './_site' directory by default - run: bundle exec jekyll build --destination ./_site2/ --baseurl "/" + run: bundle exec jekyll build --destination ./_site2/ --baseurl "" env: JEKYLL_ENV: production # - name: Build Jekyll