Skip to content

Commit 73a0465

Browse files
committed
Publish prereleases
Fixes #1155 Signed-off-by: David Thompson <davthomp@redhat.com>
1 parent b9fbe94 commit 73a0465

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

.github/workflows/release.yml

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: release
22

33
on:
4+
schedule:
5+
- cron: '0 8 * * *'
46
workflow_dispatch:
57
inputs:
68
publishPreRelease:
@@ -29,8 +31,39 @@ on:
2931
default: 'true'
3032

3133
jobs:
34+
35+
should-build-change:
36+
runs-on: ubuntu-latest
37+
outputs:
38+
repo-cache-hit: ${{ steps.cache-last-commit.outputs.cache-hit }}
39+
steps:
40+
- uses: actions/checkout@v4
41+
with:
42+
repository: "redhat-developer/vscode-yaml"
43+
fetch-depth: 2
44+
path: vscode-yaml
45+
- uses: actions/checkout@v4
46+
with:
47+
repository: "redhat-developer/yaml-language-server"
48+
fetch-depth: 2
49+
path: yaml-language-server
50+
- run: |
51+
pushd vscode-yaml
52+
git rev-parse HEAD >> ../lastCommit
53+
popd
54+
pushd yaml-language-server
55+
git rev-parse HEAD >> ../lastCommit
56+
- name: Check New Changes
57+
id: cache-last-commit
58+
uses: actions/cache@v4
59+
with:
60+
path: lastCommit
61+
key: lastCommit-${{ hashFiles('lastCommit') }}
62+
3263
packaging-job:
3364
runs-on: ubuntu-latest
65+
needs: should-build-change
66+
if: ${{ needs.should-build-change.outputs.repo-cache-hit != 'true' || github.event_name != 'schedule' }}
3467
steps:
3568
- name: Checkout vscode-yaml
3669
uses: actions/checkout@v4
@@ -39,10 +72,19 @@ jobs:
3972
with:
4073
path: release
4174
node-version: 20
75+
- name: Set version to prerelease version
76+
run: |
77+
node change-version-to-prerelease.mjs
78+
echo "publishPreReleaseFlag=--pre-release" >> $GITHUB_ENV
79+
if: ${{ github.event_name == 'schedule' || inputs.publishPreRelease == 'true'}}
4280
- name: Install dependencies
4381
run: |
4482
npm install -g typescript "@vscode/vsce" "ovsx"
4583
echo "EXT_VERSION=$(cat package.json | jq -r .version)" >> $GITHUB_ENV
84+
# Install latest yaml-language-server in the case of a prerelease
85+
- name: Update yaml-language-server
86+
if: ${{ github.event_name == 'schedule' || inputs.publishPreRelease == 'true'}}
87+
run: npm i yaml-language-server@next
4688
- name: Build vscode-yaml
4789
uses: coactions/setup-xvfb@b6b4fcfb9f5a895edadc3bc76318fae0ac17c8b3 #v1.0.1
4890
with:
@@ -56,7 +98,7 @@ jobs:
5698
run: npm test --silent
5799
- name: Package
58100
run: |
59-
vsce package -o vscode-yaml-${{ env.EXT_VERSION }}-${GITHUB_RUN_NUMBER}.vsix
101+
vsce package ${{ env.publishPreReleaseFlag }} -o vscode-yaml-${{ env.EXT_VERSION }}-${GITHUB_RUN_NUMBER}.vsix
60102
sha256sum *.vsix > vscode-yaml-${{ env.EXT_VERSION }}-${GITHUB_RUN_NUMBER}.vsix.sha256
61103
ls -lash *.vsix *.sha256
62104
- name: Upload VSIX Artifacts
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as fs from 'fs/promises';
2+
3+
function prependZero(number) {
4+
if (number > 99) {
5+
throw 'Unexpected value to prepend with zero';
6+
}
7+
return `${number < 10 ? '0' : ''}${number}`;
8+
}
9+
10+
const json = JSON.parse((await fs.readFile('./package.json')).toString());
11+
const stableVersion = json.version.match(/(\d+)\.(\d+)\.(\d+)/);
12+
const major = stableVersion[1];
13+
const minor = stableVersion[2];
14+
const date = new Date();
15+
const month = date.getMonth() + 1;
16+
const day = date.getDate();
17+
const hours = date.getHours();
18+
const patch = `${date.getFullYear()}${prependZero(month)}${prependZero(day)}${prependZero(hours)}`;
19+
const insiderPackageJson = Object.assign(json, {
20+
version: `${major}.${minor}.${patch}`,
21+
});
22+
await fs.writeFile('./package.json', JSON.stringify(insiderPackageJson, null, 2));

0 commit comments

Comments
 (0)