Skip to content

Commit e925c0b

Browse files
authored
Merge branch 'develop' into a11y-conformance-1.1
2 parents 41cbd16 + 1a8d2ff commit e925c0b

File tree

7 files changed

+101
-20
lines changed

7 files changed

+101
-20
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
go-version: '>=1.23.0'
3333
cache: false
3434
- name: Build release
35-
uses: goreleaser/goreleaser-action@5742e2a039330cbb23ebf35f046f814d4c6ff811 # v5.1.0
35+
uses: goreleaser/goreleaser-action@9ed2f89a662bf1735a48bc8557fd212fa902bebf # v6.1.0
3636
with:
3737
distribution: goreleaser
3838
version: latest
@@ -55,7 +55,7 @@ jobs:
5555
- name: Set up Docker Buildx
5656
uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.8.0
5757
- name: Build and push Docker image
58-
run: docker buildx build --platform=linux/amd64,linux/arm64,linux/arm/v7 . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
58+
run: docker buildx build --platform=linux/amd64,linux/arm64,linux/arm/v7 . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" --build-arg NO_SNAPSHOT=true
5959
- name: Log in to registry
6060
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
6161
- name: Push image
@@ -73,4 +73,5 @@ jobs:
7373
echo VERSION=$VERSION
7474
docker buildx build --push \
7575
--tag $IMAGE_ID:$VERSION \
76+
--build-arg NO_SNAPSHOT=true \
7677
--platform linux/amd64,linux/arm64,linux/arm/v7 .

.goreleaser.yaml

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Make sure to check the documentation at https://goreleaser.com
2+
version: 2
23
before:
34
hooks:
45
- go mod tidy
56
- go generate ./...
7+
gomod:
8+
proxy: true
69
builds:
710
- main: ./cmd/rwp/
811
env:
@@ -15,19 +18,11 @@ builds:
1518
- darwin
1619
goamd64:
1720
- v3
18-
19-
# - main: ./cmd/server/
20-
# env:
21-
# - CGO_ENABLED=0
22-
# id: rwp-server
23-
# binary: rwp-server
24-
# goos:
25-
# - linux
26-
# - windows
27-
# - darwin
21+
ldflags:
22+
- -s -w
2823

2924
archives:
30-
- format: tar.gz
25+
- formats: tar.gz
3126
# this name template makes the OS and Arch compatible with the results of uname.
3227
# Used to start with {{ .ProjectName }}
3328
name_template: >-
@@ -40,8 +35,8 @@ archives:
4035
# use zip for windows archives
4136
format_overrides:
4237
- goos: windows
43-
format: zip
38+
formats: ['zip']
4439
checksum:
4540
name_template: 'checksums.txt'
4641
snapshot:
47-
name_template: "{{ incpatch .Version }}-next"
42+
version_template: "{{ incpatch .Version }}-next"

Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
FROM --platform=$BUILDPLATFORM golang:1-bookworm@sha256:3149bc5043fa58cf127fd8db1fdd4e533b6aed5a40d663d4f4ae43d20386665f AS builder
22
ARG BUILDARCH TARGETOS TARGETARCH
3+
ARG NO_SNAPSHOT=false
34

45
# Install GoReleaser
5-
RUN wget --no-verbose "https://github.com/goreleaser/goreleaser/releases/download/v1.26.2/goreleaser_1.26.2_$BUILDARCH.deb"
6-
RUN dpkg -i "goreleaser_1.26.2_$BUILDARCH.deb"
6+
RUN wget --no-verbose "https://github.com/goreleaser/goreleaser/releases/download/v2.7.0/goreleaser_2.7.0_$BUILDARCH.deb"
7+
RUN dpkg -i "goreleaser_2.7.0_$BUILDARCH.deb"
78

89
# Create and change to the app directory.
910
WORKDIR /app
@@ -17,12 +18,15 @@ RUN go mod download
1718
# Copy local code to the container image.
1819
COPY . ./
1920

21+
RUN git describe --tags --always
22+
2023
# RUN git lfs pull && ls -alh publications
2124

2225
# Run goreleaser
2326
RUN --mount=type=cache,target=/root/.cache/go-build \
2427
--mount=type=cache,target=/go/pkg \
25-
GOOS=$TARGETOS GOARCH=$TARGETARCH goreleaser build --single-target --id rwp --skip=validate --snapshot --output ./rwp
28+
GOOS=$TARGETOS GOARCH=$TARGETARCH GOAMD64=v3 \
29+
goreleaser build --single-target --id rwp --skip=validate $(case "$NO_SNAPSHOT" in yes|true|1) ;; *) echo "--snapshot";; esac) --output ./rwp
2630

2731
# Run tests
2832
# FROM builder AS tester

cmd/rwp/cmd/root.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ package cmd
33
import (
44
"os"
55

6+
"github.com/readium/go-toolkit/pkg/util/version"
67
"github.com/spf13/cobra"
78
)
89

910
// rootCmd represents the base command when called without any subcommands
1011
var rootCmd = &cobra.Command{
11-
Use: "rwp",
12-
Short: "Utilities for Readium Web Publications",
12+
Use: "rwp",
13+
Short: "Utilities for Readium Web Publications",
14+
Version: version.Version,
1315
}
1416

1517
// Execute adds all child commands to the root command and sets flags appropriately.

pkg/manifest/metadata.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/go-viper/mapstructure/v2"
99
"github.com/pkg/errors"
1010
"github.com/readium/go-toolkit/pkg/internal/util"
11+
"github.com/readium/go-toolkit/pkg/util/version"
1112
)
1213

1314
// TODO replace with generic
@@ -452,6 +453,9 @@ func (m *Metadata) UnmarshalJSON(b []byte) error {
452453
return nil
453454
}
454455

456+
// If you really don't want the version info in your manifest, you can blank this value.
457+
var ToolkitVersionKey = "https://github.com/readium/go-toolkit/releases"
458+
455459
func (m Metadata) MarshalJSON() ([]byte, error) {
456460
j := make(map[string]interface{})
457461
if m.OtherMetadata != nil {
@@ -460,6 +464,10 @@ func (m Metadata) MarshalJSON() ([]byte, error) {
460464
}
461465
}
462466

467+
if ToolkitVersionKey != "" {
468+
j[ToolkitVersionKey] = version.Version
469+
}
470+
463471
if m.Presentation != nil {
464472
j["presentation"] = m.Presentation
465473
}

pkg/manifest/metadata_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import (
88
"github.com/stretchr/testify/assert"
99
)
1010

11+
func init() {
12+
ToolkitVersionKey = "" // Prevent injection of version during testing
13+
}
14+
1115
func TestMetadataUnmarshalMinimalJSON(t *testing.T) {
1216
var m Metadata
1317
assert.NoError(t, json.Unmarshal([]byte(`{"title": "Title"}`), &m))

pkg/util/version/version.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package version
2+
3+
import (
4+
"runtime/debug"
5+
"time"
6+
)
7+
8+
const toolkitRepo = "github.com/readium/go-toolkit"
9+
10+
var Version = "unknown"
11+
12+
type vcsInfo struct {
13+
VCS string
14+
Revision string
15+
Time string
16+
Modified string
17+
}
18+
19+
func init() {
20+
if info, ok := debug.ReadBuildInfo(); ok {
21+
if info.Main.Path == toolkitRepo && info.Main.Version != "(devel)" {
22+
// This is the toolkit itself
23+
Version = info.Main.Version
24+
} else {
25+
// This is a module that uses the toolkit
26+
for _, dep := range info.Deps {
27+
if dep.Path == toolkitRepo {
28+
Version = dep.Version
29+
break
30+
}
31+
}
32+
}
33+
if info.Main.Path == toolkitRepo && Version == "unknown" {
34+
// Try instead using vcs info
35+
vcs := vcsInfo{}
36+
for _, v := range info.Settings {
37+
switch v.Key {
38+
case "vcs":
39+
vcs.VCS = v.Value
40+
case "vcs.revision":
41+
vcs.Revision = v.Value
42+
case "vcs.time":
43+
vcs.Time = v.Value
44+
case "vcs.modified":
45+
vcs.Modified = v.Value
46+
}
47+
}
48+
vcsToVersion(vcs)
49+
}
50+
}
51+
}
52+
53+
func vcsToVersion(vcs vcsInfo) {
54+
if vcs.VCS != "git" || vcs.Revision == "" || vcs.Time == "" {
55+
return
56+
}
57+
58+
t, err := time.Parse(time.RFC3339, vcs.Time)
59+
if err != nil {
60+
return
61+
}
62+
63+
Version = "v0.0.0-" + t.UTC().Format("20060102150405") + "-" + vcs.Revision[:12]
64+
if vcs.Modified == "true" {
65+
Version += "+dirty"
66+
}
67+
}

0 commit comments

Comments
 (0)