Skip to content

Commit fdac5fd

Browse files
committed
ci: add release workflow
1 parent 8ded198 commit fdac5fd

20 files changed

Lines changed: 3528 additions & 194 deletions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log(Math.floor(Date.now() / 1000))

.github/workflows/release.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Manual Publish
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
releaseType:
7+
description: 'Release Type'
8+
required: true
9+
type: choice
10+
default: 'patch'
11+
options:
12+
- patch
13+
- minor
14+
- major
15+
- premajor
16+
- preminor
17+
- prepatch
18+
publishMarketplace:
19+
description: 'Publish on Visual Studio Marketplace?'
20+
required: true
21+
type: choice
22+
default: 'yes'
23+
options:
24+
- 'yes'
25+
- 'no'
26+
27+
jobs:
28+
release:
29+
permissions:
30+
contents: write
31+
id-token: write
32+
runs-on: ubuntu-latest
33+
steps:
34+
- name: 👷 Checkout
35+
uses: actions/checkout@v4
36+
with:
37+
ref: 'main'
38+
fetch-depth: 0
39+
40+
- name: 🛠️ Setup workspace
41+
uses: ./.github/workflows/actions/setup-workspace
42+
with:
43+
node-version: '20'
44+
45+
- name: 🪄 Generate Prerelease patch version number
46+
id: gen-pre-release-ver
47+
env:
48+
RELEASE_TYPE: ${{ github.event.inputs.releaseType }}
49+
run: |
50+
if [[ "${RELEASE_TYPE}" == "pre"* ]]; then
51+
VERSION="$(node .github/scripts/genPreReleaseVersion.js)"
52+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
53+
else
54+
echo "version=" >> $GITHUB_OUTPUT
55+
fi
56+
57+
- name: 🚧 Bump the version
58+
id: bump
59+
run: |
60+
pnpm lerna version ${{github.event.inputs.releaseType}} --no-push --exact --preid next --yes -m "chore(release): %s"
61+
env:
62+
NODE_ENV: production
63+
GITHUB_AUTH: ${{ secrets.GITHUB_TOKEN }}
64+
VSCODE_WDIO_PRE_RELEASE_PATCH_NUMBER: ${{ steps.gen-pre-release-ver.outputs.version }}
65+
66+
- name: 🛫 Build and publish as pre-release
67+
if: ${{ github.event.inputs.publishMarketplace == 'yes' && startsWith(github.event.inputs.releaseType, 'pre') }}
68+
run: |
69+
pnpm run publish:next
70+
env:
71+
NODE_ENV: production
72+
GITHUB_AUTH: ${{ secrets.GITHUB_TOKEN }}
73+
VSCE_PAT: ${{ secrets.VSCE_PAT }}
74+
VSCODE_WDIO_PRE_RELEASE_PATCH_NUMBER: ${{ steps.gen-pre-release-ver.outputs.version }}
75+
76+
- name: 🚀 Build and publish
77+
if: ${{ github.event.inputs.publishMarketplace == 'yes' && !startsWith(github.event.inputs.releaseType, 'pre') }}
78+
run: |
79+
pnpm run publish:next
80+
env:
81+
NODE_ENV: production
82+
VSCE_PAT: ${{ secrets.VSCE_PAT }}
83+
GITHUB_AUTH: ${{ secrets.GITHUB_TOKEN }}
84+
85+
- name: 📝 Create the Github Release
86+
run: |
87+
pnpm --filter @vscode-wdio/release run release-note
88+
env:
89+
GITHUB_AUTH: ${{ secrets.GITHUB_TOKEN }}
90+
VSCODE_WDIO_RELEASE_NOTE: ${{ steps.bump.outputs.changelog }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ node_modules
44
.vscode-test
55
.wdio-vscode-service
66
*.vsix
7+
.changelog
8+
.env
79
coverage
810
e2e/logs
911
samples/**/logs

CHANGELOG.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
# Change Log
2-
3-
All notable changes to the "wdio-vscode" extension will be documented in this file.
4-
5-
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
6-
7-
## [Unreleased]
8-
9-
- Initial release
1+
# Changelog
2+
3+
> **Tags:**
4+
>
5+
> - :boom: [Breaking Change]
6+
> - :eyeglasses: [Spec Compliancy]
7+
> - :rocket: [New Feature]
8+
> - :bug: [Bug Fix]
9+
> - :memo: [Documentation]
10+
> - :house: [Internal]
11+
> - :nail_care: [Polish]
12+
13+
---

infra/pre-package/package.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

infra/release/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@vscode-wdio/release",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"copy": "tsx ./src/copy.ts",
7+
"push": "tsx ./src/push.ts",
8+
"update-version": "tsx ./src/updatePrereleaseVersion.ts",
9+
"release-note": "tsx ./src/createRelease.ts",
10+
"changelog": "tsx ./src/changelog.ts"
11+
},
12+
"devDependencies": {
13+
"@actions/core": "^1.11.1",
14+
"@octokit/rest": "^22.0.0",
15+
"dotenv": "^16.5.0",
16+
"lerna-changelog": "^2.2.0"
17+
}
18+
}

infra/release/src/changelog.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* script to auto update CHANGELOG.md file
5+
*/
6+
import fs from 'node:fs'
7+
import path from 'node:path'
8+
import url from 'node:url'
9+
10+
import * as core from '@actions/core'
11+
import * as dotenv from 'dotenv'
12+
import shell from 'shelljs'
13+
14+
import { createPreReleaseVer, getCurrentDate } from './utils.js'
15+
import pkg from '../../../lerna.json' with { type: 'json' }
16+
17+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url))
18+
const root = path.resolve(__dirname, '..', '..', '..')
19+
const changelogPath = path.join(root, 'CHANGELOG.md')
20+
21+
dotenv.config({ path: path.join(root, '.env') })
22+
23+
if (!process.env.GITHUB_AUTH) {
24+
shell.exec('git checkout -- .')
25+
console.error(
26+
'Please export a "GITHUB_AUTH" access token to generate the changelog.\n' +
27+
'See also https://github.com/webdriverio/vscode-webdriverio/blob/main/CONTRIBUTING.md#release-new-version'
28+
)
29+
process.exit(1)
30+
}
31+
32+
const createInitial = (version: string) => {
33+
return `## v${version} (${getCurrentDate()})
34+
35+
#### :rocket: New Feature
36+
* All packages
37+
* Initial release
38+
39+
`
40+
}
41+
42+
console.log('Start generating changelog...')
43+
const result = shell.exec('pnpm exec lerna-changelog --next-version-from-metadata', { silent: true })
44+
45+
const isNoGitTags = result.stdout.match(new RegExp('fatal: No names found'))
46+
47+
if (result.code !== 0 && !isNoGitTags) {
48+
console.log('ERROR: Failed to generate changelog.')
49+
process.exit(1)
50+
}
51+
52+
/**
53+
* update local tags
54+
*/
55+
const BANNER = `
56+
#######################
57+
### ###
58+
### CHANGELOG ###
59+
### ###
60+
#######################`
61+
62+
const orgNewChangelog = isNoGitTags ? createInitial(pkg.version) : result.stdout
63+
64+
const isPreRelease = Boolean(process.env.VSCODE_WDIO_PRE_RELEASE_PATCH_NUMBER || '')
65+
66+
const newChangelog = !isPreRelease
67+
? orgNewChangelog
68+
: orgNewChangelog + `\n\n> Package as v${createPreReleaseVer(pkg.version)} `
69+
70+
let changelogContent = fs.readFileSync(changelogPath, 'utf8')
71+
changelogContent = changelogContent.replace('---', '---\n' + newChangelog)
72+
fs.writeFileSync(changelogPath, changelogContent, 'utf8')
73+
74+
console.log(BANNER)
75+
console.log(newChangelog)
76+
core.setOutput('changelog', newChangelog)

infra/release/src/createRelease.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Octokit } from '@octokit/rest'
2+
3+
import pkg from '../../../lerna.json' with { type: 'json' }
4+
/**
5+
* make GitHub release for machine readable changelog
6+
*/
7+
8+
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+
}
15+
const newChangelog = process.env.VSCODE_WDIO_RELEASE_NOTE
16+
if (!newChangelog) {
17+
console.error('The release note is not set. please set as environment variable `VSCODE_WDIO_RELEASE_NOTE`')
18+
process.exit(1)
19+
}
20+
21+
api.repos.createRelease({
22+
owner: 'webdriverio',
23+
repo: 'vscode-webdriverio',
24+
tag_name: `v${pkg.version}`,
25+
name: `v${pkg.version}`,
26+
body: newChangelog,
27+
})

infra/release/src/push.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env node
2+
/**
3+
* It seems that Lerna doesn't publish annotated tags to GitHub
4+
* after the release. This script is a little helper to ensure
5+
* this happens.
6+
*/
7+
import shell from 'shelljs'
8+
9+
import pkg from '../../../lerna.json' with { type: 'json' }
10+
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.')
16+
process.exit(0)
17+
}
18+
shell.exec('git push origin --no-verify')
19+
shell.exec(`git push origin refs/tags/v${pkg.version} -f --no-verify`)

0 commit comments

Comments
 (0)