Skip to content

Commit

Permalink
Merge branch 'develop' into a11y-conformance-1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
chocolatkey authored Feb 21, 2025
2 parents 41cbd16 + 1a8d2ff commit e925c0b
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 20 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
go-version: '>=1.23.0'
cache: false
- name: Build release
uses: goreleaser/goreleaser-action@5742e2a039330cbb23ebf35f046f814d4c6ff811 # v5.1.0
uses: goreleaser/goreleaser-action@9ed2f89a662bf1735a48bc8557fd212fa902bebf # v6.1.0
with:
distribution: goreleaser
version: latest
Expand All @@ -55,7 +55,7 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.8.0
- name: Build and push Docker image
run: docker buildx build --platform=linux/amd64,linux/arm64,linux/arm/v7 . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
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
- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push image
Expand All @@ -73,4 +73,5 @@ jobs:
echo VERSION=$VERSION
docker buildx build --push \
--tag $IMAGE_ID:$VERSION \
--build-arg NO_SNAPSHOT=true \
--platform linux/amd64,linux/arm64,linux/arm/v7 .
21 changes: 8 additions & 13 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Make sure to check the documentation at https://goreleaser.com
version: 2
before:
hooks:
- go mod tidy
- go generate ./...
gomod:
proxy: true
builds:
- main: ./cmd/rwp/
env:
Expand All @@ -15,19 +18,11 @@ builds:
- darwin
goamd64:
- v3

# - main: ./cmd/server/
# env:
# - CGO_ENABLED=0
# id: rwp-server
# binary: rwp-server
# goos:
# - linux
# - windows
# - darwin
ldflags:
- -s -w

archives:
- format: tar.gz
- formats: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
# Used to start with {{ .ProjectName }}
name_template: >-
Expand All @@ -40,8 +35,8 @@ archives:
# use zip for windows archives
format_overrides:
- goos: windows
format: zip
formats: ['zip']
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
version_template: "{{ incpatch .Version }}-next"
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
FROM --platform=$BUILDPLATFORM golang:1-bookworm@sha256:3149bc5043fa58cf127fd8db1fdd4e533b6aed5a40d663d4f4ae43d20386665f AS builder
ARG BUILDARCH TARGETOS TARGETARCH
ARG NO_SNAPSHOT=false

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

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

RUN git describe --tags --always

# RUN git lfs pull && ls -alh publications

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

# Run tests
# FROM builder AS tester
Expand Down
6 changes: 4 additions & 2 deletions cmd/rwp/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package cmd
import (
"os"

"github.com/readium/go-toolkit/pkg/util/version"
"github.com/spf13/cobra"
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "rwp",
Short: "Utilities for Readium Web Publications",
Use: "rwp",
Short: "Utilities for Readium Web Publications",
Version: version.Version,
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand Down
8 changes: 8 additions & 0 deletions pkg/manifest/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/go-viper/mapstructure/v2"
"github.com/pkg/errors"
"github.com/readium/go-toolkit/pkg/internal/util"
"github.com/readium/go-toolkit/pkg/util/version"
)

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

// If you really don't want the version info in your manifest, you can blank this value.
var ToolkitVersionKey = "https://github.com/readium/go-toolkit/releases"

func (m Metadata) MarshalJSON() ([]byte, error) {
j := make(map[string]interface{})
if m.OtherMetadata != nil {
Expand All @@ -460,6 +464,10 @@ func (m Metadata) MarshalJSON() ([]byte, error) {
}
}

if ToolkitVersionKey != "" {
j[ToolkitVersionKey] = version.Version
}

if m.Presentation != nil {
j["presentation"] = m.Presentation
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/manifest/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (
"github.com/stretchr/testify/assert"
)

func init() {
ToolkitVersionKey = "" // Prevent injection of version during testing
}

func TestMetadataUnmarshalMinimalJSON(t *testing.T) {
var m Metadata
assert.NoError(t, json.Unmarshal([]byte(`{"title": "Title"}`), &m))
Expand Down
67 changes: 67 additions & 0 deletions pkg/util/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package version

import (
"runtime/debug"
"time"
)

const toolkitRepo = "github.com/readium/go-toolkit"

var Version = "unknown"

type vcsInfo struct {
VCS string
Revision string
Time string
Modified string
}

func init() {
if info, ok := debug.ReadBuildInfo(); ok {
if info.Main.Path == toolkitRepo && info.Main.Version != "(devel)" {
// This is the toolkit itself
Version = info.Main.Version
} else {
// This is a module that uses the toolkit
for _, dep := range info.Deps {
if dep.Path == toolkitRepo {
Version = dep.Version
break
}
}
}
if info.Main.Path == toolkitRepo && Version == "unknown" {
// Try instead using vcs info
vcs := vcsInfo{}
for _, v := range info.Settings {
switch v.Key {
case "vcs":
vcs.VCS = v.Value
case "vcs.revision":
vcs.Revision = v.Value
case "vcs.time":
vcs.Time = v.Value
case "vcs.modified":
vcs.Modified = v.Value
}
}
vcsToVersion(vcs)
}
}
}

func vcsToVersion(vcs vcsInfo) {
if vcs.VCS != "git" || vcs.Revision == "" || vcs.Time == "" {
return
}

t, err := time.Parse(time.RFC3339, vcs.Time)
if err != nil {
return
}

Version = "v0.0.0-" + t.UTC().Format("20060102150405") + "-" + vcs.Revision[:12]
if vcs.Modified == "true" {
Version += "+dirty"
}
}

0 comments on commit e925c0b

Please sign in to comment.