Skip to content

Commit b362cbd

Browse files
committed
fixing Github Actions release workflow
1 parent a834f96 commit b362cbd

File tree

3 files changed

+87
-46
lines changed

3 files changed

+87
-46
lines changed

.github/workflows/binary-release.yaml

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Release varlock CLI binaries
33
# normal CI release workflow handles publishing multiple packages from the monorepo
44
# this workflow triggered by a release `[email protected]`
55
on:
6+
workflow_dispatch:
67
release:
78
types: [published]
89
tags:
@@ -32,39 +33,72 @@ jobs:
3233
# ------------------------------------------------------------
3334

3435
- name: get version from release tag
36+
if: ${{ github.event_name == 'release' }}
3537
run: |
3638
# get the full release tag name - ex: [email protected]
3739
echo "RELEASE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
3840
# get the version only from the tag - ex: 1.2.3
3941
echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/varlock@}" >> $GITHUB_ENV
42+
43+
- name: use test version (x.x.x)
44+
if: ${{ github.event_name == 'workflow_dispatch' }}
45+
run: |
46+
echo "[email protected]" >> $GITHUB_ENV
47+
echo "RELEASE_VERSION=x.x.x" >> $GITHUB_ENV
4048
41-
# necessary to bundle macos binaries from linux machine
49+
# necessary to bundle macos binaries (from linux)
4250
- name: install ldid
4351
uses: MOZGIII/install-ldid-action@v1
4452
with:
45-
tag: v2.1.5-procursus2
53+
tag: v2.1.5-procursus7
54+
# necessary for cross-arch linux binaries
55+
- name: Install qemu-user-binfmt
56+
run: |
57+
# sudo apt-get update
58+
sudo apt-get install --assume-yes qemu-user-binfmt
4659
60+
- name: build libs
61+
run: pnpm build:libs
4762
- name: build SEA dist files (CJS, no deps)
4863
run: pnpm run --filter varlock build:sea
4964

50-
- name: pkg binaries
51-
run: node scripts/build-binaries.js
52-
65+
- name: Restore pkg Node.js base binaries
66+
uses: actions/cache/restore@v4
67+
with:
68+
path: ~/.pkg-cache
69+
key: pkg-nodejs-base-binaries-node-22
70+
- name: build varlock SEA binaries (pkg)
71+
# env:
72+
# PKG_CACHE_PATH: ~/.pkg-cache
73+
run: PKG_CACHE_PATH=~/.pkg-cache node scripts/build-binaries.js
74+
- name: Cache pkg Node.js base binaries
75+
uses: actions/cache/save@v4
76+
with:
77+
path: ~/.pkg-cache
78+
key: pkg-nodejs-base-binaries-node-22
5379
- name: add binaries to GH release
54-
run: gh release upload ${{ env.RELEASE_TAG }} packages/varlock/dist-sea/*.{tar.gz,zip}
55-
56-
- name: Add release checksums
57-
uses: wangzuo/action-release-checksums@v1
80+
env:
81+
GH_TOKEN: ${{ github.token }}
82+
working-directory: packages/varlock/dist-sea
83+
run: gh release upload ${{ env.RELEASE_TAG }} *.{tar.gz,zip} checksums.txt --clobber
5884

5985
# UPDATE HOMEBREW FORMULA ---
6086
- name: checkout homebrew tap repo
6187
uses: actions/checkout@v4
6288
with:
63-
repository: "dmno-dev/homebrew-tap"
64-
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
65-
- name: 'update formula'
66-
run: node scripts/update-homebrew-formula.js ${{ env.RELEASE_VERSION }}
67-
- name: commit and push homebrew tap
89+
repository: dmno-dev/homebrew-tap
90+
token: ${{ secrets.HOMEBREW_REPO_GITHUB_ACCESS_TOKEN }}
91+
path: homebrew-tap
92+
clean: false
93+
- name: debug
94+
run: |
95+
ls -la
96+
ls -la homebrew-tap
97+
ls -la ../
98+
ls -la ../..
99+
- name: update homebrew formula
100+
run: node scripts/update-homebrew-formula.js
101+
- name: commit and push homebrew tap update
68102
run: |
69103
cd homebrew-tap
70104
git config --global user.name 'theoephraim'

scripts/build-binaries.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { execSync } from 'node:child_process';
22
import fs from 'node:fs';
3+
import path from 'node:path';
34

45
const VARLOCK_DIR = 'packages/varlock';
56
const DIST_DIR = './dist-sea';
@@ -11,6 +12,9 @@ if (!fs.existsSync(`${VARLOCK_DIR}/${executableCjsFile}`)) {
1112
}
1213

1314
const VERSION = process.env.RELEASE_VERSION;
15+
if (!VERSION) {
16+
throw new Error('RELEASE_VERSION env var must be set');
17+
}
1418

1519
// see https://github.com/yao-pkg/pkg
1620
const NODE_RANGE = 'node22';
@@ -40,19 +44,23 @@ for (const pkgTarget of TARGETS) {
4044
console.log(`Pkg-ing target: ${pkgTarget}`);
4145
const outputName = pkgTarget.replace('linuxstatic', 'linux');
4246
const targetPkgDir = `${DIST_DIR}/${outputName}`;
43-
const targetBinName = `varlock${outputName.startsWith('windows') ? '.exe' : ''}`;
47+
const targetBinName = `varlock${outputName.startsWith('win-') ? '.exe' : ''}`;
4448

4549
// run pkg to build binary
4650
exec(`./node_modules/.bin/pkg ${executableCjsFile} --public-packages "*" --public --target ${NODE_RANGE}-${pkgTarget} --output ${targetPkgDir}/${targetBinName}`);
4751

4852
// create .tar.gz file
49-
const archiveName = `varlock-${VERSION}-${outputName}.tar.gz`;
50-
exec(`tar --gzip -cf ${DIST_DIR}/${archiveName} -C ${targetPkgDir}/ .`);
51-
53+
let archiveName = `varlock-${VERSION}-${outputName}.tar.gz`;
54+
let archiveCmd = `tar --gzip -cf ${DIST_DIR}/${archiveName} -C ${targetPkgDir}/ .`;
5255
// create .zip for windows only
53-
if (outputName.startsWith('windows')) {
54-
const zipName = `varlock-${VERSION}-${outputName}.zip`;
55-
exec(`zip -j ${DIST_DIR}/${zipName} ${targetPkgDir}/${targetBinName}`);
56+
if (outputName.startsWith('win-')) {
57+
archiveName = `varlock-${VERSION}-${outputName}.zip`;
58+
archiveCmd = `zip -j ${DIST_DIR}/${archiveName} ${targetPkgDir}/${targetBinName}`;
5659
}
60+
61+
exec(archiveCmd);
62+
execSync(`sha256sum ${archiveName} >> checksums.txt`, {
63+
cwd: path.join(VARLOCK_DIR, DIST_DIR),
64+
});
5765
}
5866

scripts/update-homebrew-formula.js

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,48 @@
11
import fs from 'node:fs/promises';
22

3-
function generateVarlockFormula(version, checksums) {
4-
return `
3+
// this is run in a Github Action where this env var is set
4+
const VERSION = process.env.RELEASE_VERSION;
5+
6+
// download checksums file from release
7+
const checksumsReq = await fetch(`https://github.com/dmno-dev/varlock/releases/download/varlock@${VERSION}/checksums.txt`);
8+
const checksumsStr = await checksumsReq.text();
9+
const checksums = {};
10+
checksumsStr.split('\n').forEach((line) => {
11+
const [sha256, fileName] = line.split(' ');
12+
const fileNameParts = fileName.split('-');
13+
const platform = fileNameParts[2];
14+
const arch = fileNameParts[3];
15+
checksums[`${platform}-${arch}`] = sha256;
16+
});
17+
18+
19+
20+
const formulaSrc = `
521
class Varlock < Formula
622
desc "varlock is a tool to load and validate .env files"
723
homepage "https://varlock.dev"
8-
version "${version}"
24+
version "${VERSION}"
925
1026
on_macos do
1127
on_intel do
12-
url "https://github.com/dmno-dev/varlock/releases/download/varlock@${version}/varlock-${version}-macos-x64.tar.gz"
28+
url "https://github.com/dmno-dev/varlock/releases/download/varlock@#{version}/varlock-#{version}-macos-x64.tar.gz"
1329
sha256 "${checksums['macos-x64']}"
1430
end
1531
1632
on_arm do
17-
url "https://github.com/dmno-dev/varlock/releases/download/varlock@${version}/varlock-${version}-macos-arm64.tar.gz"
33+
url "https://github.com/dmno-dev/varlock/releases/download/varlock@#{version}/varlock-#{version}-macos-arm64.tar.gz"
1834
sha256 "${checksums['macos-arm64']}"
1935
end
2036
end
2137
2238
on_linux do
2339
on_intel do
24-
url "https://github.com/dmno-dev/varlock/releases/download/varlock@${version}/varlock-${version}-linux-x64.tar.gz"
40+
url "https://github.com/dmno-dev/varlock/releases/download/varlock@#{version}/varlock-#{version}-linux-x64.tar.gz"
2541
sha256 "${checksums['linux-x64']}"
2642
end
2743
2844
on_arm do
29-
url "https://github.com/dmno-dev/varlock/releases/download/varlock@${version}/varlock-${version}-linux-arm64.tar.gz"
45+
url "https://github.com/dmno-dev/varlock/releases/download/varlock@#{version}/varlock-#{version}-linux-arm64.tar.gz"
3046
sha256 "${checksums['linux-arm64']}"
3147
end
3248
end
@@ -40,25 +56,8 @@ class Varlock < Formula
4056
end
4157
end
4258
`;
43-
}
44-
45-
// download checksums file from release
46-
const checksumsReq = await fetch(`https://github.com/dmno-dev/varlock/releases/download/varlock@${version}/checksums.txt`);
47-
const checksumsStr = await checksumsReq.text();
48-
const checksums = {};
49-
checksumsStr.split('\n').forEach((line) => {
50-
const [sha256, fileName] = line.split(' ');
51-
const fileNameParts = fileName.split('-');
52-
const platform = fileNameParts[2];
53-
const arch = fileNameParts[3];
54-
checksums[`${platform}-${arch}`] = sha256;
55-
});
56-
57-
const args = process.argv.slice(2);
58-
const version = args[0];
5959

60-
const formulaStr = generateVarlockFormula(version, checksums);
6160

6261
// this is meant to be used in a github action
6362
// when we have checked out the homebrew-tap repo
64-
await fs.writeFile('homebrew-tap/Formula/varlock.rb', formulaStr, 'utf-8');
63+
await fs.writeFile('homebrew-tap/Formula/varlock.rb', formulaSrc, 'utf-8');

0 commit comments

Comments
 (0)