Skip to content

Commit 835180b

Browse files
committed
Testing latest release tag and build_sha
1 parent 61b0813 commit 835180b

9 files changed

+64
-44
lines changed

.github/workflows/release-insiders.yml

+3
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,6 @@ jobs:
6060
"username": "{{GITHUB_REPOSITORY}}",
6161
"text": "Release failed: https://github.com/{{GITHUB_REPOSITORY}}/actions/runs/{{GITHUB_RUN_ID}}"
6262
}
63+
record_sha:
64+
name: Record the current build sha on the newly created release
65+
runs_on: ubuntu-20.04

.github/workflows/test-upload-build-sha.yml

+17-9
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@ jobs:
1010
name: Upload the Build Shaw
1111
runs-on: ubuntu-20.04
1212
steps:
13-
- run: '[[ ${{github.sha}} == $(curl -L https://github.com/brimdata/zui-insiders/releases/download/v1.2.1-0/sha.txt) ]]'
14-
# - run: echo ${{ github.sha }} > sha.txt
15-
# - name: Upload Sha File To Release
16-
# uses: svenstaro/upload-release-action@v2
17-
# with:
18-
# file: sha.txt
19-
# tag: v1.2.1-0
20-
# repo_name: brimdata/zui-insiders
21-
# repo_token: ${{ secrets.PAT_TOKEN }}
13+
- name: Create the build_sha file
14+
run: echo ${{ github.sha }} > build_sha.txt
15+
16+
- name: Get Latest Release Tag
17+
id: latest
18+
uses: pozetroninc/[email protected]
19+
with:
20+
owner: brimdata
21+
repo: zui-insiders
22+
23+
- name: Upload build_sha File to Release
24+
uses: svenstaro/upload-release-action@v2
25+
with:
26+
file: build_sha.txt
27+
tag: ${{ steps.latest.outputs.release }}
28+
repo_name: brimdata/zui-insiders
29+
repo_token: ${{ secrets.PAT_TOKEN }}

apps/insiders/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
"version": "0.0.1",
55
"type": "commonjs",
66
"scripts": {
7+
"latest-version": "ts-node src/latest-version",
78
"inject": "ts-node src/inject",
89
"assert-update-needed": "ts-node src/update-needed"
910
},
1011
"devDependencies": {
12+
"@types/node-fetch": "^2.6.2",
1113
"fs-extra": "^10.1.0",
14+
"node-fetch": "^2.6.2",
1215
"octokit": "2.1.0",
1316
"semver": "^7.3.7"
1417
}

apps/insiders/src/commit.ts

-10
This file was deleted.

apps/insiders/src/insiders-packager.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as path from 'path';
22
import * as fs from 'fs-extra';
33
import * as semver from 'semver';
4-
import { getCurrentCommitHash } from './commit';
54

65
const p = (...args: unknown[]) => console.log('‣', ...args);
76

@@ -43,7 +42,7 @@ export class InsidersPackager {
4342
? this.stableVersion
4443
: semver.inc(this.lastVersion, 'prerelease');
4544

46-
return version + '+' + getCurrentCommitHash();
45+
return version;
4746
}
4847

4948
get strategy() {

apps/insiders/src/latest-version.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { getLatestInsidersVersion } from './latest';
2+
3+
async function main() {
4+
const latest = await getLatestInsidersVersion();
5+
console.log(latest);
6+
}
7+
8+
main();

apps/insiders/src/latest.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
import { Octokit } from 'octokit';
2+
import fetch from 'node-fetch';
23

34
const gh = new Octokit();
45

56
export async function getLatestInsidersVersion() {
6-
const release = await gh.rest.repos.getLatestRelease({
7+
const release = await getRelease();
8+
// Remove the v
9+
return release.data.tag_name.slice(1);
10+
}
11+
12+
export async function getLatestInsidersSha() {
13+
const release = await getRelease();
14+
const { tag_name } = release.data;
15+
const resp = await fetch(shaUrl(tag_name));
16+
const sha = await resp.text();
17+
return sha.trim();
18+
}
19+
20+
function shaUrl(tag: string) {
21+
return `https://github.com/brimdata/zui-insiders/releases/download/${tag}/sha.txt`;
22+
}
23+
24+
function getRelease() {
25+
return gh.rest.repos.getLatestRelease({
726
owner: 'brimdata',
827
repo: 'zui-insiders',
928
});
10-
11-
return release.data.tag_name.slice(1); // Remove the v
1229
}

apps/insiders/src/update-needed.ts

+10-20
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,17 @@
1-
import { getCurrentCommitHash } from './commit';
2-
import { getLatestInsidersVersion } from './latest';
3-
import * as semver from 'semver';
1+
import { getLatestInsidersSha } from './latest';
42

5-
function extractCommitFromVersion(version: string) {
6-
const parts = semver.parse(version);
3+
async function main() {
4+
const currentSha = process.env['GITHUB_SHA'];
5+
const releaseSha = await getLatestInsidersSha();
76

8-
if (parts && parts.build.length === 1) {
9-
return parts.build[0];
10-
} else {
11-
return null;
12-
}
13-
}
7+
console.log('Last Release:', releaseSha);
8+
console.log(' Current:', currentSha);
149

15-
async function main() {
16-
const version = await getLatestInsidersVersion();
17-
const head = getCurrentCommitHash();
18-
const lastCommit = extractCommitFromVersion(version);
19-
const updateNeeded = !(head === lastCommit);
20-
if (updateNeeded) {
21-
console.log('Update needed');
22-
} else {
23-
console.log('Update not needed');
10+
if (releaseSha.trim() === currentSha) {
11+
console.log('No Update Needed');
2412
process.exit(1);
13+
} else {
14+
console.log('Continue Update');
2515
}
2616
}
2717

yarn.lock

+2
Original file line numberDiff line numberDiff line change
@@ -10807,7 +10807,9 @@ __metadata:
1080710807
version: 0.0.0-use.local
1080810808
resolution: "insiders@workspace:apps/insiders"
1080910809
dependencies:
10810+
"@types/node-fetch": ^2.6.2
1081010811
fs-extra: ^10.1.0
10812+
node-fetch: ^2.6.2
1081110813
octokit: 2.1.0
1081210814
semver: ^7.3.7
1081310815
languageName: unknown

0 commit comments

Comments
 (0)