Skip to content

Commit bd624bb

Browse files
committed
ci: add dry run capability to release workflow
[skip ci]
1 parent 83b3ed5 commit bd624bb

9 files changed

Lines changed: 72 additions & 27 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
console.log(Math.floor(Date.now() / 1000))
1+
console.log(Math.floor(Date.now() / 10000))

.github/workflows/release.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: Manual Publish
22

3+
run-name: Manual Publish${{ github.event.inputs.dryRun == 'yes' && ' (DRY RUN)' || '' }}
4+
35
on:
46
workflow_dispatch:
57
inputs:
@@ -12,9 +14,10 @@ on:
1214
- patch
1315
- minor
1416
- major
15-
- premajor
16-
- preminor
1717
- prepatch
18+
- preminor
19+
- premajor
20+
- prerelease
1821
publishMarketplace:
1922
description: 'Publish on Visual Studio Marketplace?'
2023
required: true
@@ -23,6 +26,14 @@ on:
2326
options:
2427
- 'yes'
2528
- 'no'
29+
dryRun:
30+
description: 'Dry run? If yes, this workflow will NOT push to remote and NOT publish the extension.'
31+
required: true
32+
type: choice
33+
default: 'no'
34+
options:
35+
- 'yes'
36+
- 'no'
2637

2738
jobs:
2839
release:
@@ -59,7 +70,6 @@ jobs:
5970
run: |
6071
pnpm lerna version ${{github.event.inputs.releaseType}} --no-push --exact --preid next --yes -m "chore(release): %s"
6172
env:
62-
NODE_ENV: production
6373
GITHUB_AUTH: ${{ secrets.GITHUB_TOKEN }}
6474
VSCODE_WDIO_PRE_RELEASE_PATCH_NUMBER: ${{ steps.gen-pre-release-ver.outputs.version }}
6575

@@ -68,8 +78,9 @@ jobs:
6878
run: |
6979
pnpm run publish:next
7080
env:
71-
GITHUB_AUTH: ${{ secrets.GITHUB_TOKEN }}
7281
VSCE_PAT: ${{ secrets.VSCE_PAT }}
82+
GITHUB_AUTH: ${{ secrets.GITHUB_TOKEN }}
83+
VSCODE_WDIO_DRY_RUN: ${{ github.event.inputs.dryRun }}
7384
VSCODE_WDIO_PRE_RELEASE_PATCH_NUMBER: ${{ steps.gen-pre-release-ver.outputs.version }}
7485

7586
- name: 🚀 Build and publish
@@ -79,10 +90,12 @@ jobs:
7990
env:
8091
VSCE_PAT: ${{ secrets.VSCE_PAT }}
8192
GITHUB_AUTH: ${{ secrets.GITHUB_TOKEN }}
93+
VSCODE_WDIO_DRY_RUN: ${{ github.event.inputs.dryRun }}
8294

8395
- name: 📝 Create the Github Release
8496
run: |
8597
pnpm --filter @vscode-wdio/release run release-note
8698
env:
8799
GITHUB_AUTH: ${{ secrets.GITHUB_TOKEN }}
100+
VSCODE_WDIO_DRY_RUN: ${{ github.event.inputs.dryRun }}
88101
VSCODE_WDIO_RELEASE_NOTE: ${{ steps.bump.outputs.changelog }}

infra/release/src/createRelease.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,45 @@
1+
import path from 'node:path'
2+
import url from 'node:url'
3+
14
import { Octokit } from '@octokit/rest'
5+
import * as dotenv from 'dotenv'
26

37
import pkg from '../../../lerna.json' with { type: 'json' }
8+
49
/**
510
* make GitHub release for machine readable changelog
611
*/
12+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url))
13+
const root = path.resolve(__dirname, '..', '..', '..')
14+
dotenv.config({ path: path.join(root, '.env') })
715

816
const api = new Octokit({ auth: process.env.GITHUB_AUTH })
9-
10-
const isGithubActions = Boolean(process.env.GITHUB_ACTIONS)
11-
if (!isGithubActions) {
12-
console.log('\nSkip creating the Github Release because this is not running on the Github Actions.')
13-
process.exit(0)
14-
}
1517
const newChangelog = process.env.VSCODE_WDIO_RELEASE_NOTE
1618
if (!newChangelog) {
1719
console.error('The release note is not set. please set as environment variable `VSCODE_WDIO_RELEASE_NOTE`')
1820
process.exit(1)
1921
}
2022

23+
const repo = process.env.GITHUB_REPOSITORY || ''
24+
const [owner, repoName] = repo.split('/')
25+
if (owner !=='webdriverio' || repoName !== 'vscode-webdriverio'){
26+
console.error(`This repository is not correct repository. (Current: ${repo})`)
27+
process.exit(1)
28+
}
29+
30+
if (process.env.VSCODE_WDIO_DRY_RUN === 'yes') {
31+
console.log('*---- DRY RUN ----*')
32+
console.log(`tag_name: v${pkg.version}`)
33+
console.log(`name: v${pkg.version}`)
34+
console.log(newChangelog)
35+
process.exit(0)
36+
}
37+
console.log(`Creating Github Release: v${pkg.version}`)
2138
api.repos.createRelease({
2239
owner: 'webdriverio',
2340
repo: 'vscode-webdriverio',
2441
tag_name: `v${pkg.version}`,
2542
name: `v${pkg.version}`,
2643
body: newChangelog,
2744
})
45+
console.log(`Created Github Release: v${pkg.version}`)

infra/release/src/push.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import shell from 'shelljs'
88

99
import pkg from '../../../lerna.json' with { type: 'json' }
1010

11-
const isGithubActions = Boolean(process.env.GITHUB_ACTIONS)
12-
13-
console.log('\nPushing release tag...')
14-
if (!isGithubActions) {
15-
console.log('\nSkip pushing because this is not running on the Github Actions.')
11+
if (process.env.VSCODE_WDIO_DRY_RUN === 'yes') {
12+
console.log('dryRun is `yes`. Skip the push.')
1613
process.exit(0)
1714
}
15+
16+
console.log('Pushing the commit and tag.')
1817
shell.exec('git push origin --no-verify')
1918
shell.exec(`git push origin refs/tags/v${pkg.version} -f --no-verify`)
19+
console.log('Successfully pushed.')
20+

infra/release/src/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export const createPreReleaseVer = (version: string) => {
1313
if (!patchNumber) {
1414
throw new Error('VSCODE_WDIO_PRE_RELEASE_PATCH_NUMBER is not set. Please check the environment variables.')
1515
}
16-
const newVersion = version.split('.').slice(0, 2)
17-
newVersion.push(patchNumber)
16+
const [major, minor, patch] = version.split('.')
17+
const newVersion = [major, minor]
18+
newVersion.push(`${patch.split('-')[0]}${patchNumber}`.slice(0, 9))
1819
return `${newVersion.join('.')}`
1920
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"coverage": "vitest --run --coverage",
3232
"graph": "pnpm run build --graph assets/build.png",
3333
"version": "pnpm --filter @vscode-wdio/release run changelog && git add CHANGELOG.md",
34+
"postversion": "git show",
3435
"postinstall": "run-s postinstall:*",
3536
"postinstall:husky": "husky"
3637
},

packages/vscode-webdriverio/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"prepackage:copy": "pnpm --filter @vscode-wdio/release run copy",
2929
"prepackage:update-version": "pnpm --filter @vscode-wdio/release run update-version",
3030
"package": "vsce package",
31-
"publish": "vsce publish",
31+
"publish": "tsx ./scripts/publish.ts",
3232
"postpublish": "pnpm --filter @vscode-wdio/release run push",
3333
"package:next": "pnpm run package --pre-release",
3434
"publish:next": "pnpm run publish --pre-release",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env node
2+
import shell from 'shelljs'
3+
4+
if (process.env.VSCODE_WDIO_DRY_RUN === 'yes') {
5+
console.log('dryRun is `yes`. Skip the publish.')
6+
process.exit(0)
7+
}
8+
9+
const args = process.argv.slice(2)
10+
const command = `vsce publish ${args.join(' ')}`
11+
12+
console.log(`Running: ${command}`)
13+
shell.exec(command)
14+
console.log('Successfully published.')

turbo.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"$schema": "https://turbo.build/schema.json",
3+
"globalEnv": ["GITHUB_*", "VSCODE_WDIO_*", "VSCE_PAT"],
34
"tasks": {
45
"clean": {},
56
"build": {
@@ -16,20 +17,16 @@
1617
"cache": false
1718
},
1819
"vscode-webdriverio#package": {
19-
"dependsOn": ["build:production"],
20-
"env": ["GITHUB_ACTIONS", "GITHUB_AUTH", "VSCE_PAT"]
20+
"dependsOn": ["build:production"]
2121
},
2222
"vscode-webdriverio#publish": {
23-
"dependsOn": ["package"],
24-
"env": ["GITHUB_ACTIONS", "GITHUB_AUTH", "VSCE_PAT"]
23+
"dependsOn": ["package"]
2524
},
2625
"vscode-webdriverio#package:next": {
27-
"dependsOn": ["build:production"],
28-
"env": ["GITHUB_ACTIONS", "GITHUB_AUTH", "VSCE_PAT", "VSCODE_WDIO_PRE_RELEASE_PATCH_NUMBER"]
26+
"dependsOn": ["build:production"]
2927
},
3028
"vscode-webdriverio#publish:next": {
31-
"dependsOn": ["package:next"],
32-
"env": ["GITHUB_ACTIONS", "GITHUB_AUTH", "VSCE_PAT"]
29+
"dependsOn": ["package:next"]
3330
}
3431
}
3532
}

0 commit comments

Comments
 (0)