version.go autoupdate

This commit is contained in:
Kusakabe Si 2021-12-27 10:58:42 +00:00 committed by KusakabeSi
parent e69d6cc5aa
commit 3a1fad0366
5 changed files with 109 additions and 33 deletions

View File

@ -9,7 +9,8 @@ jobs:
name: Build for ${{ matrix.distro }} x86_64 and mipsle
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v2
with:
@ -53,6 +54,8 @@ jobs:
- arch: armv7
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: uraimo/run-on-arch-action@v2.0.5
name: Build artifact
id: build

View File

@ -2,17 +2,35 @@ name: Publish
on:
push:
tags:
- '*'
workflow_dispatch:
concurrency:
group: build-${{ github.ref }}
cancel-in-progress: true
jobs:
x86_64:
runs-on: ubuntu-20.04
name: Build for ${{ matrix.distro }} x86_64 and mipsle
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Retrieve version
shell: bash
run: |
VERSION=$(git describe --abbrev=0)
echo "::set-output name=VERSION::$VERSION"
id: version
- name: Print main version
shell: bash
env:
VERSION: ${{ steps.version.outputs.VERSION }}
run: |
git describe
git describe --abbrev=0
git describe --tags --abbrev=0
echo $VERSION
- name: Set up Go
uses: actions/setup-go@v2
with:
@ -29,16 +47,6 @@ jobs:
run: |
make all static vpp
- name: Commit & Push version.go
uses: actions-js/push@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: main
force: true
author_email: si@kskb.eu.org
author_name: KusakabeSi
message: update version.go
- uses: actions/upload-artifact@v2
with:
name: etherguard-x86_64
@ -51,7 +59,8 @@ jobs:
file: etherguard-go
overwrite: true
asset_name: etherguard-go-x86_64
tag: ${{ github.ref }}
release_name: ${{ steps.version.outputs.VERSION }}
tag: ${{ steps.version.outputs.VERSION }}
- name: Upload x86_64 dynamic vpp build
uses: svenstaro/upload-release-action@v2
@ -60,7 +69,8 @@ jobs:
file: etherguard-go-vpp
overwrite: true
asset_name: etherguard-go-vpp-x86_64
tag: ${{ github.ref }}
release_name: ${{ steps.version.outputs.VERSION }}
tag: ${{ steps.version.outputs.VERSION }}
- name: Upload x86_64 static build
uses: svenstaro/upload-release-action@v2
@ -69,7 +79,8 @@ jobs:
file: etherguard-go-static
overwrite: true
asset_name: etherguard-go-static-x86_64
tag: ${{ github.ref }}
release_name: ${{ steps.version.outputs.VERSION }}
tag: ${{ steps.version.outputs.VERSION }}
- name: Build mipsle
run: |
@ -89,7 +100,8 @@ jobs:
file: etherguard-go
asset_name: etherguard-go-mipsle
overwrite: true
tag: ${{ github.ref }}
release_name: ${{ steps.version.outputs.VERSION }}
tag: ${{ steps.version.outputs.VERSION }}
- name: Upload mipsle static build
uses: svenstaro/upload-release-action@v2
@ -98,7 +110,8 @@ jobs:
file: etherguard-go-static
asset_name: etherguard-go-static-mipsle
overwrite: true
tag: ${{ github.ref }}
release_name: ${{ steps.version.outputs.VERSION }}
tag: ${{ steps.version.outputs.VERSION }}
multi-arch:
runs-on: ubuntu-20.04
@ -110,6 +123,23 @@ jobs:
- arch: armv7
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Retrieve version
shell: bash
run: |
VERSION=$(git describe --abbrev=0)
echo "::set-output name=VERSION::$VERSION"
id: version
- name: Print main version
shell: bash
env:
VERSION: ${{ steps.version.outputs.VERSION }}
run: |
git describe
git describe --abbrev=0
git describe --tags --abbrev=0
echo $VERSION
- uses: uraimo/run-on-arch-action@v2.0.5
name: Build artifact
id: build
@ -161,7 +191,8 @@ jobs:
file: artifacts/${{ matrix.arch }}/etherguard-go
asset_name: etherguard-go-${{ matrix.arch }}
overwrite: true
tag: ${{ github.ref }}
release_name: ${{ steps.version.outputs.VERSION }}
tag: ${{ steps.version.outputs.VERSION }}
- name: Upload ${{ matrix.arch }} dynamic vpp build
if: ${{ matrix.arch == 'aarch64' }}
@ -171,7 +202,8 @@ jobs:
file: artifacts/${{ matrix.arch }}/etherguard-go
asset_name: etherguard-go-vpp-${{ matrix.arch }}
overwrite: true
tag: ${{ github.ref }}
release_name: ${{ steps.version.outputs.VERSION }}
tag: ${{ steps.version.outputs.VERSION }}
- name: Upload ${{ matrix.arch }} static build
uses: svenstaro/upload-release-action@v2
@ -180,4 +212,5 @@ jobs:
file: artifacts/${{ matrix.arch }}/etherguard-go-static
asset_name: etherguard-go-static-${{ matrix.arch }}
overwrite: true
tag: ${{ github.ref }}
release_name: ${{ steps.version.outputs.VERSION }}
tag: ${{ steps.version.outputs.VERSION }}

38
.github/workflows/update-version.yaml vendored Normal file
View File

@ -0,0 +1,38 @@
name: Update version
on:
workflow_dispatch:
jobs:
update-version:
name: Update version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Test git command
shell: bash
run: |
# setup the username and email. I tend to use 'GitHub Actions Bot' with no email by default
cd $GITHUB_WORKSPACE
git --version
git config user.name "GitHub Actions Bot"
git config user.email "<>"
git status
git describe --always
- name: Update version.go
run: |
cd $GITHUB_WORKSPACE
tag=$(git describe 2>/dev/null)
ver=$(printf 'package main\n\nconst Version = "%s"\n' "$tag")
echo "$ver" > version.go
shell: bash
- name: Commit & Push changes
uses: actions-js/push@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: master
author_email: si@kskb.eu.org
author_name: KusakabeSi
message: update version.go

View File

@ -1,6 +1,7 @@
PREFIX ?= /usr
DESTDIR ?=
BINDIR ?= $(PREFIX)/bin
FULLTAG ?= $(shell git describe)
export GO111MODULE := on
all: generate-version-and-build
@ -9,8 +10,8 @@ MAKEFLAGS += --no-print-directory
generate-version-and-build:
@export GIT_CEILING_DIRECTORIES="$(realpath $(CURDIR)/..)" && \
tag="$$(git describe 2>/dev/null)" && \
ver="$$(printf 'package main\n\nconst Version = "%s"\n' "$$tag")" && \
tag="$$(git describe --tags --abbrev=0 2>/dev/null)" && \
ver="$$(printf 'package main\n\nvar Version = "%s"\n' "$$tag")" && \
[ "$$(cat version.go 2>/dev/null)" != "$$ver" ] && \
echo "$$ver" > version.go || true
@$(MAKE) etherguard-go
@ -19,18 +20,19 @@ etherguard-go: $(wildcard *.go) $(wildcard */*.go)
go mod download && \
go mod tidy && \
go mod vendor && \
go build -v -o "$@"
go build -v -ldflags '-X main.Version=$(FULLTAG)' -o "$@"
etherguard-go-static: $(wildcard *.go) $(wildcard */*.go)
go mod download && \
go mod tidy && \
go mod vendor && \
CGO_ENABLED=0 go build -a -trimpath -ldflags '-s -w -extldflags "-static"' -v -o "$@"
CGO_ENABLED=0 go build -a -trimpath -ldflags '-X main.Version=$(FULLTAG) -s -w -extldflags "-static"' -v -o "$@"
vpp:
@export GIT_CEILING_DIRECTORIES="$(realpath $(CURDIR)/..)" && \
tag="$$(git describe 2>/dev/null)" && \
ver="$$(printf 'package main\n\nconst Version = "%s"\n' "$$tag")" && \
tag="$$(git describe --tags --abbrev=0 2>/dev/null)" && \
fulltag="$$(git describe 2>/dev/null)" && \
ver="$$(printf 'package main\n\nvar Version = "%s"\n' "$$tag")" && \
[ "$$(cat version.go 2>/dev/null)" != "$$ver" ] && \
echo "$$ver" > version.go || true
@$(MAKE) etherguard-go-vpp
@ -41,12 +43,13 @@ etherguard-go-vpp: $(wildcard *.go) $(wildcard */*.go)
go mod tidy && \
go mod vendor && \
patch -p0 -i govpp_remove_crcstring_check.patch && \
go build -v -tags vpp -o "$@"
go build -v -tags vpp -ldflags '-X main.Version=$(FULLTAG)' -o "$@"
static:
@export GIT_CEILING_DIRECTORIES="$(realpath $(CURDIR)/..)" && \
tag="$$(git describe 2>/dev/null)" && \
ver="$$(printf 'package main\n\nconst Version = "%s"\n' "$$tag")" && \
tag="$$(git describe --tags --abbrev=0 2>/dev/null)" && \
fulltag="$$(git describe 2>/dev/null)" && \
ver="$$(printf 'package main\n\nvar Version = "%s"\n' "$$tag")" && \
[ "$$(cat version.go 2>/dev/null)" != "$$ver" ] && \
echo "$$ver" > version.go || true
@$(MAKE) etherguard-go-static
@ -61,6 +64,5 @@ clean:
rm -f etherguard-go
rm -f etherguard-go-static
rm -f etherguard-go-vpp
rm -f etherguard-go-vpp-static
.PHONY: all clean test install generate-version-and-build

View File

@ -1,3 +1,3 @@
package main
const Version = "v0.3.4"
var Version = "v0.3.5"