Skip to content

Commit

Permalink
Merge pull request #236 from gctools-outilsgc/pr-sync-fix
Browse files Browse the repository at this point in the history
Fix synchronize for PR redeploy
  • Loading branch information
doug0102 authored Feb 1, 2024
2 parents 2b4b7a2 + cec122c commit 0943504
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
7 changes: 6 additions & 1 deletion .bicep/pr-instance.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,7 +36,11 @@ resource appService 'Microsoft.Web/sites@2022-03-01' = {
}
{
name: 'WEBSITE_NODE_DEFAULT_VERSION'
value: '16.14.2'
value: nodeVersion
}
{
name: 'WEBSITE_WEBDEPLOY_USE_SCM'
value: 'true'
}
]
}
Expand Down
13 changes: 6 additions & 7 deletions .github/workflows/deploy-pr.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# 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

on:
pull_request:
types: [opened, reopened] # TODO: synchronize
types: [opened, reopened, synchronize]
branches: main

env:
Expand Down Expand Up @@ -51,18 +52,16 @@ 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"
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
shell: bash
run: gh auth login --with-token <<< ${{ env.ACCESS_TOKEN }}

- uses: actions/checkout@v3
- name: Create Secret
run: |
escaped_profile=$(printf "%q" "${{ env.PROFILE }}")
gh secret set "${{ env.SECRET_NAME }}" --body "$escaped_profile"
run: gh secret set "${{ env.SECRET_NAME }}" --body "${{ env.PROFILE }}"
env:
PROFILE: ${{ steps.get-publishing-profile.outputs.profile }}

Expand Down
19 changes: 16 additions & 3 deletions src/scripts/nodeSyncWorkflows.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -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}`);
}
}
});

0 comments on commit 0943504

Please sign in to comment.