Skip to content

Commit

Permalink
Generate plugin version from git describe
Browse files Browse the repository at this point in the history
  • Loading branch information
torarnv committed Apr 7, 2024
1 parent de6ea90 commit 85be167
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ build/
docs-partials/
docs.zip
vendor/
version.go
12 changes: 11 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
env:
- CGO_ENABLED=0
- API_VERSION={{ if index .Env "API_VERSION" }}{{ .Env.API_VERSION }}{{ else }}x5.0{{ end }}

before:
hooks:
- make

builds:
-
mod_timestamp: '{{ .CommitTimestamp }}'
flags:
- -trimpath
ldflags:
- '-s -w -X {{ .ModulePath }}/version.Version={{.Version}} -X {{ .ModulePath }}/version.VersionPrerelease= '
- '-s -w'
binary: '{{ .ProjectName }}_v{{ .Version }}_{{ .Env.API_VERSION }}_{{ .Os }}_{{ .Arch }}'
goos:
- netbsd
Expand All @@ -28,6 +33,11 @@ builds:
- goos: darwin
goarch: '386'

snapshot:
name_template: "{{ if eq .Summary .Tag }}{{ .Version }}{{ else }}{{ incpatch .Version }}-dev{{ end }}"

# {{ incpatch .Version }}-dev-{{ .Tag }}

archives:
- format: zip
files:
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ $(HCL2_GENERATED): %.hcl2spec.go : %.go

.PHONY: build
build: $(HCL2_GENERATED)
@go generate main.go
@go build -o $(BINARY)

.PHONY: install
Expand Down
19 changes: 14 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
// Copyright (c) Tor Arne Vestbø
// SPDX-License-Identifier: MPL-2.0

//go:generate go run git.rootprojects.org/root/go-gitver/[email protected] --outfile version.go

package main

import (
"fmt"
"os"
"regexp"

"github.com/hashicorp/packer-plugin-sdk/plugin"
"github.com/hashicorp/packer-plugin-sdk/version"
packerVersion "github.com/hashicorp/packer-plugin-sdk/version"

"github.com/torarnv/packer-plugin-ipsw/datasource"
)

var (
Version = "0.1.2"
VersionPrerelease = ""
PluginVersion = version.InitializePluginVersion(Version, VersionPrerelease)
// Generated at build time
commit = "0000000"
version = "0.0.0-pre0+0000000"
date = "0000-00-00T00:00:00+0000"
)

func main() {
pps := plugin.NewSet()

regex := regexp.MustCompile("(.*)?-pre.*$")
version = regex.ReplaceAllString(version, "$1-dev")
pps.SetVersion(packerVersion.InitializePluginVersion(version, ""))

pps.RegisterDatasource(plugin.DEFAULT_NAME, new(ipsw.Datasource))
pps.SetVersion(PluginVersion)

err := pps.Run()
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
Expand Down

0 comments on commit 85be167

Please sign in to comment.