Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix synchronize for PR redeploy #236

Merged
merged 16 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}`);
}
}
});
Loading