Skip to content

Add GitHub Actions workflow for Azure Functions deployment #1316

Add GitHub Actions workflow for Azure Functions deployment

Add GitHub Actions workflow for Azure Functions deployment #1316

name: Update Package Version
permissions:
contents: write # Changed from 'read' to 'write' to allow pushing commits
pull-requests: write
packages: write
on:
pull_request:
types:
- opened
- edited
- labeled
- unlabeled
jobs:
update-version:
name: Update Package Version
runs-on: windows-latest
if: contains(github.event.pull_request.labels.*.name, 'minor') || contains(github.event.pull_request.labels.*.name, 'patch')
steps:
- uses: step-security/harden-runner@6c439dc8bdf85cadbbce9ed30d1c7b959517bc49 # v2.12.2
with:
egress-policy: audit
- name: Determine version type
id: version_type
run: |
if ($env:GITHUB_EVENT_PULL_REQUEST_LABELS -contains "major") {
$env:VERSION_TYPE = "major"
} elseif ($env:GITHUB_EVENT_PULL_REQUEST_LABELS -contains "minor") {
$env:VERSION_TYPE = "minor"
} elseif ($env:GITHUB_EVENT_PULL_REQUEST_LABELS -contains "patch") {
$env:VERSION_TYPE = "patch"
} else {
$env:VERSION_TYPE = ""
}
shell: pwsh
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }} # Added token for push permissions
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
shell: pwsh
- name: Update package version and push tag
if: env.VERSION_TYPE != ''
run: |
# Get current version from package.json
$packageJson = Get-Content "package.json" | ConvertFrom-Json
$currentVersion = $packageJson.version
Write-Host "Current version: $currentVersion"
# Update package.json version and create git tag
$newVersion = npm version $env:VERSION_TYPE
$newVersionString = $newVersion.TrimStart('v')
Write-Host "New version: $newVersionString"
# Update version.ts file
$versionTs = Get-Content "src/version.ts"
$updatedVersionTs = $versionTs -replace 'export const packageVersion = ".*"', "export const packageVersion = `"$newVersionString`""
$updatedVersionTs | Set-Content "src/version.ts"
Write-Host "Updated version.ts"
# Show git status for debugging
git status
# Add version.ts to the commit
git add src/version.ts
git commit --amend --no-edit
Write-Host "Updated commit with version.ts"
shell: pwsh
env:
VERSION_TYPE: ${{ env.VERSION_TYPE }}
- name: Push changes
if: env.VERSION_TYPE != ''
run: |
git push origin HEAD:main
shell: pwsh