Skip to content

Commit e463bc9

Browse files
committed
fix: improve the nightly and release workflow
1 parent d8df408 commit e463bc9

File tree

11 files changed

+134
-132
lines changed

11 files changed

+134
-132
lines changed

.github/workflows/nightly.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,24 @@ jobs:
8686
containerfiles: |
8787
./packages/web/infra/Containerfile
8888
image: ${{ env.REGISTRY_IMAGE }}
89-
tags: ${{ steps.meta.outputs.tags }}
90-
working-directory: packages/web
89+
tags: ${{ steps.tag.outputs.tag }}
9190
oci: true
9291
platforms: linux/amd64,linux/arm64
9392
labels: |
9493
org.opencontainers.image.source=${{ github.repository }}
9594
org.opencontainers.image.revision=${{ github.sha }}
9695
org.opencontainers.image.created=${{ github.event.head_commit.timestamp }}
9796
98-
9997
- name: Push To GHCR
10098
id: push-to-registry
10199
uses: redhat-actions/push-to-registry@v2
102100
with:
103101
image: ${{ steps.build-container.outputs.image }}
104-
tags: ${{ steps.build-container.outputs.tags }}
102+
tags: ${{ steps.build-container.outputs.tags || steps.tag.outputs.tag }}
105103
registry: ghcr.io
106104
username: ${{ github.actor }}
107105
password: ${{ secrets.GITHUB_TOKEN }}
108106

107+
109108
- name: Print image URL
110109
run: echo "Image pushed to ${{ steps.push-to-registry.outputs.registry-paths }}"

.github/workflows/release-packages.yml

Lines changed: 66 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@ on:
44
workflow_dispatch:
55
inputs:
66
packages:
7-
description: 'Packages to release (comma-separated, or "all" for all packages)'
7+
description: 'Packages to release (comma-separated, or "all")'
88
required: false
99
default: 'all'
10+
bump:
11+
description: 'Semver bump (patch | minor | major)'
12+
required: false
13+
default: 'patch'
1014

1115
jobs:
1216
release:
1317
runs-on: ubuntu-latest
1418
permissions:
15-
contents: read
16-
id-token: write # <-- required for JSR OIDC
19+
contents: write # we commit the bumped versions back
20+
id-token: write # required for JSR OIDC
21+
env:
22+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
1723
steps:
1824
- name: Checkout code
1925
uses: actions/checkout@v4
@@ -29,21 +35,16 @@ jobs:
2935
node-version: 22
3036
cache: pnpm
3137
cache-dependency-path: '**/pnpm-lock.yaml'
38+
registry-url: 'https://registry.npmjs.org'
3239

3340
- name: Install dependencies
3441
run: pnpm install --frozen-lockfile
3542

36-
- name: Configure npm auth
37-
env:
38-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
39-
run: |
40-
pnpm config set //registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}
41-
pnpm config set registry https://registry.npmjs.org/
42-
4343
- name: Resolve package list
4444
id: pkgs
4545
shell: bash
4646
run: |
47+
set -euo pipefail
4748
if [ "${{ github.event.inputs.packages }}" = "all" ] || [ -z "${{ github.event.inputs.packages }}" ]; then
4849
mapfile -t TARGETS < <(ls -d packages/* | grep -v 'packages/web')
4950
else
@@ -52,61 +53,91 @@ jobs:
5253
fi
5354
printf '%s\n' "${TARGETS[@]}" | paste -sd, - > targets.txt
5455
echo "list=$(cat targets.txt)" >> "$GITHUB_OUTPUT"
56+
echo "Targets: $(cat targets.txt)"
5557
56-
- name: Build selected packages (tsdown)
58+
- name: Bump package.json versions (no git tag)
59+
shell: bash
5760
run: |
61+
set -euo pipefail
62+
BUMP="${{ github.event.inputs.bump }}"
5863
IFS=',' read -ra TARGETS <<< "${{ steps.pkgs.outputs.list }}"
5964
for dir in "${TARGETS[@]}"; do
60-
echo "Building $dir"
61-
pnpm --filter "./$dir" run build
65+
if [ -f "$dir/package.json" ]; then
66+
echo "Bumping $dir -> $BUMP"
67+
(cd "$dir" && npm version "$BUMP" --no-git-tag-version --allow-same-version)
68+
fi
6269
done
6370
64-
- name: Sync jsr.json version from package.json
71+
- name: Generate jsr.json from package.json (pkg-to-jsr)
72+
shell: bash
6573
run: |
74+
set -euo pipefail
6675
IFS=',' read -ra TARGETS <<< "${{ steps.pkgs.outputs.list }}"
6776
for dir in "${TARGETS[@]}"; do
68-
if [ -f "$dir/jsr.json" ] && [ -f "$dir/package.json" ]; then
69-
PKG_VER=$(jq -r .version "$dir/package.json")
70-
jq --arg v "$PKG_VER" '.version = $v' "$dir/jsr.json" > "$dir/jsr.json.tmp" && mv "$dir/jsr.json.tmp" "$dir/jsr.json"
71-
echo "Updated $dir/jsr.json to version $PKG_VER"
77+
if [ -f "$dir/package.json" ]; then
78+
echo "Generating jsr.json for $dir"
79+
pnpm dlx pkg-to-jsr --root "$dir"
80+
# # Optional: show result
81+
# jq -C . "$dir/jsr.json" || cat "$dir/jsr.json"
7282
fi
7383
done
7484
85+
86+
- name: Commit version bumps
87+
shell: bash
88+
run: |
89+
set -euo pipefail
90+
git config user.name "github-actions[bot]"
91+
git config user.email "github-actions[bot]@users.noreply.github.com"
92+
git add packages/*/package.json packages/*/jsr.json 2>/dev/null || true
93+
if ! git diff --cached --quiet; then
94+
git commit -m "chore(release): bump package versions (${{ github.event.inputs.bump }})"
95+
git push
96+
else
97+
echo "No changes to commit."
98+
fi
99+
100+
- name: Build selected packages
101+
shell: bash
102+
run: |
103+
set -euo pipefail
104+
IFS=',' read -ra TARGETS <<< "${{ steps.pkgs.outputs.list }}"
105+
for dir in "${TARGETS[@]}"; do
106+
echo "Building $dir"
107+
pnpm --filter "./$dir" run build
108+
done
109+
75110
- name: Publish to JSR (OIDC)
111+
shell: bash
76112
run: |
77113
set -euo pipefail
78114
IFS=',' read -ra TARGETS <<< "${{ steps.pkgs.outputs.list }}"
79115
for dir in "${TARGETS[@]}"; do
80116
if [ -f "$dir/jsr.json" ]; then
81117
echo "Publishing $dir to JSR via OIDC…"
82-
cd "$dir"
83-
[ -d dist ] || pnpm run build
84-
if ! npx --yes jsr publish 2>&1 | tee jsr_publish.log; then
85-
echo "JSR publish failed for $dir. Error output:"
86-
cat jsr_publish.log
87-
fi
88-
cd - >/dev/null
118+
( cd "$dir"
119+
[ -d dist ] || pnpm run build
120+
npx --yes jsr publish
121+
)
89122
fi
90123
done
91124
92-
- name: Replace exports entry in package.json
125+
- name: Configure npm auth
93126
run: |
94-
tmp=$(mktemp)
95-
jq '.exports["."] = "./dist/mod.mjs"' package.json > "$tmp" \
96-
&& mv "$tmp" package.json
127+
pnpm config set //registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}
128+
pnpm config set registry https://registry.npmjs.org/
97129
98130
- name: Publish to npm
131+
shell: bash
99132
run: |
100133
set -euo pipefail
101134
IFS=',' read -ra TARGETS <<< "${{ steps.pkgs.outputs.list }}"
102135
for dir in "${TARGETS[@]}"; do
103136
if [ -f "$dir/package.json" ]; then
104137
echo "Publishing $dir to npm…"
105-
cd "$dir"
106-
[ -d dist ] || pnpm run build
107-
npm publish --access public || echo "npm publish failed for $dir"
108-
cd - >/dev/null
138+
( cd "$dir"
139+
[ -d dist ] || pnpm run build
140+
npm publish --access public
141+
)
109142
fi
110143
done
111-
112-

.github/workflows/release-web.yml

Lines changed: 40 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,11 @@ jobs:
3030
release-web:
3131
runs-on: ubuntu-latest
3232
steps:
33-
- name: Checkout Code
33+
- name: Checkout code
3434
uses: actions/checkout@v4
3535
with:
36-
# For manual runs, allow building a chosen ref (branch/tag/SHA)
3736
ref: ${{ inputs.ref != '' && inputs.ref || github.ref }}
3837

39-
- name: Determine tag & latest flag
40-
id: meta
41-
shell: bash
42-
run: |
43-
# Determine TAG
44-
if [ "${{ github.event_name }}" = "release" ]; then
45-
TAG="${{ github.event.release.tag_name }}"
46-
# Push "latest" only for full releases (not prereleases)
47-
if [ "${{ github.event.release.prerelease }}" = "true" ]; then
48-
PUSH_LATEST="false"
49-
else
50-
PUSH_LATEST="true"
51-
fi
52-
elif [ -n "${{ inputs.tag_name }}" ]; then
53-
TAG="${{ inputs.tag_name }}"
54-
PUSH_LATEST="false"
55-
else
56-
SHA="$(git rev-parse --short=12 HEAD)"
57-
TAG="adhoc-${SHA}"
58-
PUSH_LATEST="false"
59-
fi
60-
61-
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
62-
echo "push_latest=$PUSH_LATEST" >> "$GITHUB_OUTPUT"
63-
echo "Resolved tag: $TAG (push_latest=$PUSH_LATEST)"
64-
6538
- name: Setup pnpm
6639
uses: pnpm/action-setup@v4
6740
with:
@@ -81,63 +54,62 @@ jobs:
8154
working-directory: packages/web
8255
run: pnpm run build
8356

84-
- name: Create Web App Release Archive
57+
- name: Create release archive
8558
working-directory: packages/web
8659
run: pnpm run package
8760

88-
- name: Upload Web App Archive (artifact)
61+
- name: Upload archive (artifact)
8962
uses: actions/upload-artifact@v4
9063
with:
91-
name: web-build-${{ steps.meta.outputs.tag }}
92-
if-no-files-found: error
64+
name: web-build
9365
path: packages/web/dist/build.tar
66+
if-no-files-found: error
9467

95-
- name: Attach Web Archive to GitHub Release
68+
- name: Attach archive to GitHub Release
9669
if: ${{ github.event_name == 'release' || inputs.attach_to_release == true }}
70+
uses: softprops/action-gh-release@v2
71+
with:
72+
files: packages/web/dist/build.tar
73+
tag_name: ${{ github.event_name == 'release' && github.event.release.tag_name || inputs.tag_name }}
74+
fail_on_unmatched_files: true
9775
env:
9876
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
99-
shell: bash
100-
run: |
101-
if [ "${{ github.event_name }}" = "release" ]; then
102-
TAG="${{ steps.meta.outputs.tag }}"
103-
else
104-
if [ -z "${{ inputs.tag_name }}" ]; then
105-
echo "attach_to_release requested but no tag_name provided." >&2
106-
exit 1
107-
fi
108-
TAG="${{ inputs.tag_name }}"
109-
fi
110-
gh release upload "$TAG" packages/web/dist/build.tar --clobber
77+
78+
- name: Docker metadata (tags & labels)
79+
id: meta
80+
uses: docker/metadata-action@v5
81+
with:
82+
images: ${{ env.REGISTRY_IMAGE }}
83+
tags: |
84+
# For release events, use the release tag (e.g. v1.2.3)
85+
type=raw,value=${{ github.event.release.tag_name }},enable=${{ github.event_name == 'release' }}
86+
# For manual runs with a provided tag_name
87+
type=raw,value=${{ inputs.tag_name }},enable=${{ github.event_name == 'workflow_dispatch' && inputs.tag_name != '' }}
88+
# For manual runs without tag_name, fall back to adhoc-<shortsha>
89+
type=sha,format=short,prefix=adhoc-,enable=${{ github.event_name == 'workflow_dispatch' && inputs.tag_name == '' }}
90+
# Add "latest" only for full releases (not prereleases)
91+
type=raw,value=latest,enable=${{ github.event_name == 'release' && github.event.release.prerelease == false }}
11192
11293
- name: Set up QEMU
11394
uses: docker/setup-qemu-action@v3
11495

115-
- name: Build Container Image
116-
id: build-container
117-
uses: redhat-actions/buildah-build@v2
118-
with:
119-
containerfiles: |
120-
./packages/web/infra/Containerfile
121-
image: ${{ env.REGISTRY_IMAGE }}
122-
tags: latest,${{ steps.meta.outputs.tag }}
123-
oci: true
124-
platforms: linux/amd64,linux/arm64
96+
- name: Set up Buildx
97+
uses: docker/setup-buildx-action@v3
12598

126-
- name: Push Container to GHCR
127-
id: push-to-registry
128-
if: ${{ github.event_name == 'release' && github.event.release.prerelease == false }}
129-
uses: redhat-actions/push-to-registry@v2
99+
- name: Build and (maybe) push image
100+
uses: docker/build-push-action@v6
130101
with:
131-
image: ${{ steps.build-container.outputs.image }}
132-
tags: ${{ steps.build-container.outputs.tags }}
133-
registry: ghcr.io
134-
username: ${{ github.actor }}
135-
password: ${{ secrets.GITHUB_TOKEN }}
102+
context: .
103+
file: ./packages/web/infra/Containerfile
104+
platforms: linux/amd64,linux/arm64
105+
push: ${{ github.event_name == 'release' && github.event.release.prerelease == false }}
106+
tags: ${{ steps.meta.outputs.tags }}
107+
labels: ${{ steps.meta.outputs.labels }}
136108

137-
- name: Output Image URL
109+
- name: Output image refs
138110
if: ${{ github.event_name == 'release' && github.event.release.prerelease == false }}
139-
run: echo "🖼️ Image pushed to ${{ steps.push-to-registry.outputs.registry-paths }}"
111+
run: "echo \"🖼️ Pushed: ${{ steps.meta.outputs.tags }}\""
140112

141-
- name: Explain no image URL
113+
- name: Explain no image push
142114
if: ${{ !(github.event_name == 'release' && github.event.release.prerelease == false) }}
143-
run: echo "ℹ️ No image pushed (this was a prerelease or manual run)."
115+
run: echo "ℹ️ No image pushed (prerelease or manual run)."

packages/core/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
".": "./mod.ts"
77
},
88
"type": "module",
9-
"main": "./dist/mod.mjs",
10-
"module": "./dist/mod.mjs",
11-
"types": "./dist/mod.d.mts",
9+
"main": "./dist/mod.js",
10+
"module": "./dist/mod.js",
11+
"types": "./dist/mod.d.ts",
1212
"license": "GPL-3.0-only",
1313
"tsdown": {
1414
"entry": "mod.ts",

packages/transport-deno/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"exports": {
66
".": "./mod.ts"
77
},
8-
"main": "./dist/mod.mjs",
9-
"module": "./dist/mod.mjs",
10-
"types": "./dist/mod.d.mts",
8+
"main": "./dist/mod.js",
9+
"module": "./dist/mod.js",
10+
"types": "./dist/mod.d.ts",
1111
"license": "GPL-3.0-only",
1212
"tsdown": {
1313
"entry": "mod.ts",

packages/transport-http/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
"LICENSE",
1313
"dist"
1414
],
15-
"main": "./dist/mod.mjs",
16-
"module": "./dist/mod.mjs",
17-
"types": "./dist/mod.d.mts",
15+
"main": "./dist/mod.js",
16+
"module": "./dist/mod.js",
17+
"types": "./dist/mod.d.ts",
1818
"license": "GPL-3.0-only",
1919
"tsdown": {
2020
"entry": "mod.ts",

packages/transport-node-serial/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
"version": "0.0.1",
44
"description": "NodeJS-specific serial transport layer for Meshtastic web applications.",
55
"exports": {
6-
".": "./dist/mod.mjs"
6+
".": "./dist/mod.js"
77
},
8-
"main": "./dist/mod.mjs",
9-
"module": "./dist/mod.mjs",
10-
"types": "./dist/mod.d.mts",
8+
"main": "./dist/mod.js",
9+
"module": "./dist/mod.js",
10+
"types": "./dist/mod.d.ts",
1111

1212
"license": "GPL-3.0-only",
1313
"tsdown": {

0 commit comments

Comments
 (0)