Skip to content

Commit 9599859

Browse files
authored
chore: adds CI/CD workflows for publishing nightly and release npm packages (#400)
Integration via OIDC - Github Actions -- This pull request introduces new CI/CD workflows for publishing nightly and release npm packages, and improves the version update automation. It adds separate pipelines for nightly pre-releases on both Azure DevOps and GitHub Actions, creates a dedicated workflow for publishing tagged releases, and enhances the version update workflow to keep `src/version.ts` in sync with `package.json`. There are also minor fixes to permissions and workflow configuration. **New CI/CD workflows for releases and nightly builds:** * Added `.github/workflows/pre-release.yml` to automate nightly pre-release npm package publishing via GitHub Actions, including versioning with a nightly date suffix and publishing under `nightly` and `pre-release` tags. * Added `.azuredevops/pipelines/pre-release.yml` for a nightly pre-release pipeline in Azure DevOps, mirroring the GitHub workflow for teams using Azure DevOps. * Introduced `.github/workflows/release.yml` to publish npm packages when a new version tag is pushed, ensuring releases are built, tested, and published with provenance. **Improvements to version update workflow:** * Enhanced `.github/workflows/version-update.yml` to update both `package.json` and `src/version.ts` with the new version, amending the commit to include both files, and fixed permissions to allow pushing commits. [[1]](diffhunk://#diff-3b9e6af6c59b5ee7e732a6427df7a69ffaeab3db2a1427779532d4cd21044728L4-R4) [[2]](diffhunk://#diff-3b9e6af6c59b5ee7e732a6427df7a69ffaeab3db2a1427779532d4cd21044728L40-L59) * Updated the checkout and setup-node steps to use the latest versions and configured Git for automated commits. **Minor fix:** * Corrected a typo in the version type assignment (`mamjor` instead of `major`) in the version determination step.
1 parent bd99d30 commit 9599859

File tree

4 files changed

+188
-8
lines changed

4 files changed

+188
-8
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
trigger: none
2+
3+
schedules:
4+
- cron: "0 22 * * *" # Runs every day at 22:00 UTC
5+
displayName: Nightly Pre-release
6+
branches:
7+
include:
8+
- main
9+
10+
variables:
11+
- group: npm-credentials
12+
- name: nightlyVersion
13+
value: $[counter(format('{0:yyyy}{0:MM}{0:dd}', pipeline.startTime), 1)]
14+
15+
jobs:
16+
- job: PreReleaseNightly
17+
pool:
18+
vmImage: "windows-latest"
19+
20+
steps:
21+
- task: UseNode@1
22+
inputs:
23+
version: "20"
24+
checkLatest: false
25+
retryCountOnDownloadFails: 2
26+
27+
- task: npmAuthenticate@0
28+
inputs:
29+
workingFile: .npmrc
30+
customEndpoint: "npmjs-service-connection"
31+
displayName: Authenticate with npm registry
32+
33+
- task: PowerShell@2
34+
displayName: Create .npmrc with auth token
35+
inputs:
36+
targetType: "inline"
37+
script: |
38+
"//registry.npmjs.org/:_authToken=$(NPM_TOKEN)" | Out-File -FilePath ".npmrc" -Encoding utf8
39+
"@azure-devops:registry=https://registry.npmjs.org/" | Add-Content -Path ".npmrc"
40+
41+
- task: Npm@1
42+
inputs:
43+
command: "ci"
44+
displayName: Install clean dependencies
45+
46+
- task: PowerShell@2
47+
displayName: Update package version for nightly release
48+
inputs:
49+
targetType: "inline"
50+
script: |
51+
# Read version.ts to get base version
52+
$versionTs = Get-Content "src/version.ts"
53+
$baseVersionLine = $versionTs | Where-Object { $_ -match 'export const packageVersion = "(.+)"' }
54+
$baseVersion = $Matches[1]
55+
56+
# Generate date suffix (YYYYMMDD format)
57+
$dateString = Get-Date -Format "yyyyMMdd"
58+
59+
$packageJson = Get-Content "package.json" | ConvertFrom-Json
60+
$nightlyVersion = "$baseVersion-nightly.$dateString"
61+
$packageJson.version = $nightlyVersion
62+
$packageJson | ConvertTo-Json -Depth 100 | Set-Content "package.json"
63+
Write-Host "Updated version to: $nightlyVersion"
64+
65+
- task: Npm@1
66+
inputs:
67+
command: "custom"
68+
customCommand: "run build"
69+
displayName: Build the project
70+
71+
- task: Npm@1
72+
inputs:
73+
command: "custom"
74+
customCommand: "publish --access public --registry=https://registry.npmjs.org/ --tag nightly --tag pre-release"
75+
displayName: Publish nightly package to npmjs under @azure-devops org scope

.github/workflows/pre-release.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Nightly Pre-release
2+
3+
permissions:
4+
contents: read
5+
id-token: write # Required for OIDC
6+
7+
on:
8+
schedule:
9+
- cron: "0 22 * * *" # Runs every day at 22:00 UTC (midnight CEST during daylight saving time)
10+
workflow_dispatch:
11+
12+
jobs:
13+
pre-release:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: "20"
24+
registry-url: "https://registry.npmjs.org"
25+
26+
# npm 11.5.1 or later is required for OIDC integration
27+
- name: Update npm
28+
run: npm install -g npm@latest
29+
30+
- name: Install dependencies
31+
run: npm ci
32+
33+
- name: Build the project
34+
run: npm run build --if-present
35+
36+
- name: Run tests
37+
run: npm test
38+
39+
- name: Publish to npm with nightly version
40+
run: |
41+
DATE_STRING=$(date +%Y%m%d)
42+
CURRENT_VERSION=$(npm pkg get version | tr -d '"')
43+
npm version "$CURRENT_VERSION-nightly.$DATE_STRING" --no-git-tag-version
44+
npm publish --access public --tag nightly --tag pre-release --provenance

.github/workflows/release.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Publish Package
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
workflow_dispatch:
8+
9+
permissions:
10+
id-token: write # Required for OIDC
11+
contents: read
12+
13+
jobs:
14+
publish:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- uses: actions/setup-node@v4
20+
with:
21+
node-version: "20"
22+
registry-url: "https://registry.npmjs.org"
23+
24+
# Ensure npm 11.5.1 or later is installed
25+
- name: Update npm
26+
run: npm install -g npm@latest
27+
- run: npm ci
28+
- run: npm run build --if-present
29+
- run: npm test
30+
- run: npm publish --provenance

.github/workflows/version-update.yml

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Update Package Version
22

33
permissions:
4-
contents: read
4+
contents: write # Changed from 'read' to 'write' to allow pushing commits
55
pull-requests: write
66
packages: write
77

@@ -27,7 +27,9 @@ jobs:
2727
- name: Determine version type
2828
id: version_type
2929
run: |
30-
if ($env:GITHUB_EVENT_PULL_REQUEST_LABELS -contains "minor") {
30+
if ($env:GITHUB_EVENT_PULL_REQUEST_LABELS -contains "major") {
31+
$env:VERSION_TYPE = "major"
32+
} elseif ($env:GITHUB_EVENT_PULL_REQUEST_LABELS -contains "minor") {
3133
$env:VERSION_TYPE = "minor"
3234
} elseif ($env:GITHUB_EVENT_PULL_REQUEST_LABELS -contains "patch") {
3335
$env:VERSION_TYPE = "patch"
@@ -37,25 +39,54 @@ jobs:
3739
shell: pwsh
3840

3941
- name: Checkout code
40-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
42+
uses: actions/checkout@v4
43+
with:
44+
token: ${{ secrets.GITHUB_TOKEN }} # Added token for push permissions
4145

4246
- name: Set up Node.js
43-
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
47+
uses: actions/setup-node@v4
4448
with:
4549
node-version: 20
4650

51+
- name: Configure Git
52+
run: |
53+
git config user.name "github-actions[bot]"
54+
git config user.email "github-actions[bot]@users.noreply.github.com"
55+
shell: pwsh
56+
4757
- name: Update package version and push tag
4858
if: env.VERSION_TYPE != ''
4959
run: |
60+
# Get current version from package.json
61+
$packageJson = Get-Content "package.json" | ConvertFrom-Json
62+
$currentVersion = $packageJson.version
63+
Write-Host "Current version: $currentVersion"
64+
65+
# Update package.json version and create git tag
5066
$newVersion = npm version $env:VERSION_TYPE
51-
git tag "v$newVersion"
52-
git push origin "v$newVersion"
67+
$newVersionString = $newVersion.TrimStart('v')
68+
Write-Host "New version: $newVersionString"
69+
70+
# Update version.ts file
71+
$versionTs = Get-Content "src/version.ts"
72+
$updatedVersionTs = $versionTs -replace 'export const packageVersion = ".*"', "export const packageVersion = `"$newVersionString`""
73+
$updatedVersionTs | Set-Content "src/version.ts"
74+
Write-Host "Updated version.ts"
75+
76+
# Show git status for debugging
77+
git status
78+
79+
# Add version.ts to the commit
80+
git add src/version.ts
81+
git commit --amend --no-edit
82+
Write-Host "Updated commit with version.ts"
83+
5384
shell: pwsh
85+
env:
86+
VERSION_TYPE: ${{ env.VERSION_TYPE }}
5487

5588
- name: Push changes
5689
if: env.VERSION_TYPE != ''
5790
run: |
58-
git config user.name "github-actions[bot]"
59-
git config user.email "github-actions[bot]@users.noreply.github.com"
6091
git push origin HEAD:main
6192
shell: pwsh

0 commit comments

Comments
 (0)