Skip to content

Commit 0ce9c00

Browse files
authored
Merge pull request #1 from invopop/cli-trial
Become the base of operations: gobl CLI + gobl.dev web/API + wasm
2 parents 9438380 + 12deaea commit 0ce9c00

280 files changed

Lines changed: 40328 additions & 113 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.air.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ tmp_dir = "tmp"
33

44
[build]
55
args_bin = []
6-
bin = "./tmp/gobl-dev"
7-
cmd = "templ generate && go build -o ./tmp/gobl-dev ."
6+
bin = "./tmp/gobl.dev"
7+
cmd = "templ generate && go build -o ./tmp/gobl.dev ./cmd/gobl.dev"
88
delay = 1000
99
exclude_dir = ["tmp", "vendor"]
1010
exclude_file = []

‎.github/workflows/lint.yaml‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Lint
2+
on:
3+
push:
4+
tags:
5+
- v*
6+
branches:
7+
- main
8+
pull_request:
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
lint:
15+
name: golangci-lint
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Check out code
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Go
23+
uses: actions/setup-go@v5
24+
with:
25+
go-version-file: "go.mod"
26+
27+
- name: Lint
28+
uses: golangci/golangci-lint-action@v8

‎.github/workflows/publish-npm.yaml‎

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#
2+
# Publish the gobl-worker package to NPM. Runs automatically after a
3+
# successful Release CLI run, and can be re-run manually (workflow_dispatch)
4+
# to retry a failed publish without re-running the full release.
5+
#
6+
# Split into two jobs so the privileged publish never executes repository
7+
# code (CodeQL "untrusted checkout in a privileged context"):
8+
# - build: unprivileged (contents: read, no id-token / secrets). Checks
9+
# out the released commit, builds the package, and packs a tarball.
10+
# - publish: privileged (id-token: write for NPM OIDC trusted publishing).
11+
# Only downloads the pre-built tarball and publishes it with
12+
# --ignore-scripts; it never checks out or runs repo code.
13+
#
14+
name: Publish NPM
15+
16+
on:
17+
workflow_run:
18+
workflows: ["Release CLI"]
19+
types: [completed]
20+
workflow_dispatch:
21+
22+
permissions:
23+
contents: read
24+
25+
jobs:
26+
build:
27+
name: Build gobl-worker
28+
# Run on a successful upstream Release CLI (restricted to main, the only
29+
# branch Release CLI runs on), or whenever triggered manually.
30+
if: ${{ github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main') }}
31+
runs-on: ubuntu-latest
32+
permissions:
33+
contents: read # no secrets / id-token here, so building the code is safe
34+
outputs:
35+
tag: ${{ steps.npm-tag.outputs.tag }}
36+
steps:
37+
# No explicit `ref`: for workflow_run this is the default branch and for
38+
# workflow_dispatch the selected ref. Referencing
39+
# github.event.workflow_run.head_sha here would count as untrusted data
40+
# for CodeQL (cache-poisoning/poisonable-step); the released commit is
41+
# pinned via its tag in the next step instead.
42+
- name: Checkout
43+
uses: actions/checkout@v4
44+
with:
45+
fetch-depth: "0" # need tags to resolve the released version
46+
persist-credentials: false
47+
48+
- name: Resolve released version
49+
id: version
50+
run: |
51+
version="$(git describe --tags --abbrev=0)"
52+
echo "Building gobl-worker $version"
53+
# Build exactly the released commit, even if the branch has moved on.
54+
git checkout --detach "refs/tags/${version}"
55+
echo "version=$version" >> "$GITHUB_OUTPUT"
56+
57+
- name: Set up Go
58+
uses: actions/setup-go@v5
59+
with:
60+
go-version-file: "go.mod"
61+
# workflow_run executes in the default branch's cache scope; with
62+
# caching on, the npm build steps below could poison caches restored
63+
# by privileged workflows (CodeQL cache-poisoning/poisonable-step).
64+
cache: false
65+
66+
# wasm_exec.js is gitignored; copy it from the active Go install before
67+
# the npm build bundles it.
68+
- name: Copy Go WASM Exec
69+
run: cp "$(go env GOROOT)/lib/wasm/wasm_exec.js" ./wasm/worker/src
70+
71+
- name: Install Node.js
72+
uses: actions/setup-node@v4
73+
with:
74+
node-version: 22.x
75+
76+
- name: Build and pack gobl-worker
77+
working-directory: ./wasm/worker
78+
run: |
79+
npm ci
80+
npm version --no-git-tag-version "${{ steps.version.outputs.version }}"
81+
npm run build
82+
npm pack
83+
84+
# npm refuses to publish a prerelease to the default `latest` dist-tag;
85+
# derive `rc`/`beta`/etc. from the version, else `latest`.
86+
- name: Determine npm dist-tag
87+
id: npm-tag
88+
run: |
89+
v="${{ steps.version.outputs.version }}"
90+
if [[ "$v" =~ -([a-z]+) ]]; then
91+
tag="${BASH_REMATCH[1]}"
92+
else
93+
tag="latest"
94+
fi
95+
echo "Using npm dist-tag: $tag"
96+
echo "tag=$tag" >> "$GITHUB_OUTPUT"
97+
98+
- name: Upload package tarball
99+
uses: actions/upload-artifact@v4
100+
with:
101+
name: gobl-worker-pkg
102+
path: ./wasm/worker/*.tgz
103+
if-no-files-found: error
104+
105+
publish:
106+
name: Publish to NPM
107+
needs: build
108+
runs-on: ubuntu-latest
109+
permissions:
110+
id-token: write # NPM OIDC trusted publishing
111+
contents: read
112+
steps:
113+
- name: Download package tarball
114+
uses: actions/download-artifact@v4
115+
with:
116+
name: gobl-worker-pkg
117+
118+
- name: Install Node.js
119+
uses: actions/setup-node@v4
120+
with:
121+
node-version: 22.x
122+
# Intentionally no `registry-url`: setup-node would otherwise write
123+
# a `.npmrc` with an `_authToken` entry that blocks the OIDC
124+
# trusted-publisher exchange.
125+
126+
# npx fetches npm 11 (required for OIDC trusted publishing) without
127+
# touching the global install. The prebuilt tarball is published with
128+
# scripts disabled, so no repository code runs in this privileged job.
129+
- name: Publish to NPM
130+
run: npx -y npm@11 publish ./*.tgz --tag "${{ needs.build.outputs.tag }}" --ignore-scripts

‎.github/workflows/release-cli.yaml‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#
2+
# Fully-automated release of the GOBL CLI and wasm. On every push to main it
3+
# bumps the semver tag (patch by default; use #minor / #major in a commit
4+
# message to bump further), then builds and publishes the `gobl` CLI and the
5+
# wasm binary as GitHub Release assets via GoReleaser, and uploads the wasm to
6+
# cdn.gobl.org.
7+
#
8+
# The gobl-worker npm package is published separately by publish-npm.yaml,
9+
# which runs on successful completion of this workflow and can be re-run
10+
# manually to retry a failed publish.
11+
#
12+
name: Release CLI
13+
14+
on:
15+
workflow_dispatch:
16+
push:
17+
branches:
18+
- main
19+
20+
permissions:
21+
contents: write # create tags and releases
22+
23+
concurrency:
24+
group: release-cli
25+
cancel-in-progress: false
26+
27+
jobs:
28+
release:
29+
name: Release CLI & wasm
30+
runs-on: ubuntu-latest
31+
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v4
35+
with:
36+
fetch-depth: "0" # all commits, for semver + changelog
37+
38+
- name: Bump version and push tag
39+
id: tag
40+
uses: anothrNick/github-tag-action@1.75.0
41+
env:
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
DEFAULT_BUMP: patch
44+
WITH_V: "true"
45+
RELEASE_BRANCHES: main
46+
# Floor the CLI versioning above core's 0.4xx series. Applies only
47+
# when no tags exist yet, so the first release lands at v0.500.1
48+
# (INITIAL_VERSION is the pre-bump base); every release stays >= 0.500.0.
49+
INITIAL_VERSION: "0.500.0"
50+
51+
- name: Set up Go
52+
uses: actions/setup-go@v5
53+
with:
54+
go-version-file: "go.mod"
55+
56+
- name: Run GoReleaser (CLI + wasm)
57+
uses: goreleaser/goreleaser-action@v6
58+
with:
59+
distribution: goreleaser
60+
version: latest
61+
args: release --clean
62+
env:
63+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64+
# Cloudflare R2 (cdn.gobl.org) credentials for the wasm upload.
65+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
66+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

‎.github/workflows/test.yaml‎

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
name: Test
1+
name: Test Go
22

33
on:
44
pull_request:
55
push:
6+
tags:
7+
- v*
68
branches:
79
- main
810

@@ -11,16 +13,36 @@ permissions:
1113

1214
jobs:
1315
test:
16+
name: Test
1417
runs-on: ubuntu-latest
18+
env:
19+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
20+
1521
steps:
16-
- uses: actions/checkout@v4
22+
- name: Check out code
23+
uses: actions/checkout@v4
1724

18-
- uses: actions/setup-go@v5
25+
- name: Set up Go
26+
uses: actions/setup-go@v5
1927
with:
2028
go-version-file: "go.mod"
2129

22-
- name: Build
23-
run: go build ./...
30+
- name: Install Dependencies
31+
env:
32+
GOPROXY: https://proxy.golang.org,direct
33+
run: go mod download
34+
35+
- name: Test
36+
run: go test -race -coverprofile=coverage.out -covermode=atomic ./...
2437

25-
- name: Vet
26-
run: go vet ./...
38+
- name: Coverage summary
39+
run: go tool cover -func=coverage.out | tail -1 >> "$GITHUB_STEP_SUMMARY"
40+
41+
# Runs once the repo is enabled on Codecov and a CODECOV_TOKEN secret is
42+
# added; skipped (keeping the build green) until then.
43+
- name: Upload coverage reports to Codecov
44+
if: env.CODECOV_TOKEN != ''
45+
uses: codecov/codecov-action@v5.1.2
46+
with:
47+
token: ${{ env.CODECOV_TOKEN }}
48+
slug: invopop/gobl.dev

‎.github/workflows/update-gobl.yaml‎

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

‎.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@
1818
/tmp
1919

2020
/gobl.dev
21+
/gobl
22+
/serve
23+
go.work
24+
go.work.sum

0 commit comments

Comments
 (0)