Skip to content

Commit

Permalink
feature: Add version command.
Browse files Browse the repository at this point in the history
This commit adds a version command so that folks know what version of
pixlet they are currently using.
  • Loading branch information
betterengineering committed Apr 14, 2022
1 parent 1c0a863 commit f61493c
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 64 deletions.
126 changes: 67 additions & 59 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- main
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
- "v[0-9]+.[0-9]+.[0-9]+"

jobs:
lint:
Expand All @@ -16,7 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.16.12'
go-version: "1.16.12"

- name: Install buildifier
run: make install-buildifier
Expand All @@ -33,52 +33,60 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: '1.16.12'
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: "1.16.12"

- name: Install Node
uses: actions/setup-node@v3
with:
node-version: "16"

- name: Install Node
uses: actions/setup-node@v3
with:
node-version: '16'
- name: Checkout code
uses: actions/checkout@v3

- name: Checkout code
uses: actions/checkout@v3
- name: Install Linux dependencies
if: matrix.os == 'ubuntu-latest'
run: sudo ./scripts/setup-linux.sh

- name: Install Linux dependencies
if: matrix.os == 'ubuntu-latest'
run: sudo ./scripts/setup-linux.sh
- name: Install macOS dependencies
if: matrix.os == 'macos-latest'
run: ./scripts/setup-macos.sh

- name: Install macOS dependencies
if: matrix.os == 'macos-latest'
run: ./scripts/setup-macos.sh
- name: Install frontend dependencies
run: npm install

- name: Install frontend dependencies
run: npm install
- name: Build frontend
run: npm run build

- name: Build frontend
run: npm run build
- name: Build
run: make build

- name: Build
run: make build
- name: Test
run: make test

- name: Test
run: make test
- name: Set pixlet version
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}

- name: Build Release Linux
if: matrix.os == 'ubuntu-latest'
run: make release-linux
- name: Build Release Linux
if: matrix.os == 'ubuntu-latest'
run: make release-linux
env:
PIXLET_VERSION: ${{ steps.vars.outputs.tag }}

- name: Build Release macOS
if: matrix.os == 'macos-latest'
run: make release-macos
- name: Build Release macOS
if: matrix.os == 'macos-latest'
run: make release-macos
env:
PIXLET_VERSION: ${{ steps.vars.outputs.tag }}

- name: Upload Release Artifacts
uses: actions/upload-artifact@v3
with:
name: release-artifacts
path: build
- name: Upload Release Artifacts
uses: actions/upload-artifact@v3
with:
name: release-artifacts
path: build

create-release:
name: Create Github Release
Expand All @@ -88,25 +96,25 @@ jobs:
if: startsWith(github.ref, 'refs/tags/')

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v3
with:
go-version: '1.16.12'

- name: Fetch Release Artifacts
uses: actions/download-artifact@v3
with:
name: release-artifacts

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release
env:
GITHUB_TOKEN: ${{ secrets.TIDBYT_GITHUB_TOKEN }}
DISCORD_WEBHOOK_ID: ${{ secrets.DISCORD_WEBHOOK_ID }}
DISCORD_WEBHOOK_TOKEN: ${{ secrets.DISCORD_WEBHOOK_TOKEN }}
- name: Checkout Code
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v3
with:
go-version: "1.16.12"

- name: Fetch Release Artifacts
uses: actions/download-artifact@v3
with:
name: release-artifacts

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release
env:
GITHUB_TOKEN: ${{ secrets.TIDBYT_GITHUB_TOKEN }}
DISCORD_WEBHOOK_ID: ${{ secrets.DISCORD_WEBHOOK_ID }}
DISCORD_WEBHOOK_TOKEN: ${{ secrets.DISCORD_WEBHOOK_TOKEN }}
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
GIT_COMMIT = $(shell git rev-list -1 HEAD)

ifeq ($(OS),Windows_NT)
BINARY = pixlet.exe
LDFLAGS = -ldflags="-s -extldflags=-static"
LDFLAGS = -ldflags="-s -extldflags=-static -X 'tidbyt.dev/pixlet/cmd.Version=$(GIT_COMMIT)'"
else
BINARY = pixlet
LDFLAGS = -ldflags="-X 'tidbyt.dev/pixlet/cmd.Version=$(GIT_COMMIT)'"
endif

test:
Expand All @@ -17,7 +20,7 @@ bench:
go test -benchmem -benchtime=20s -bench BenchmarkRunAndRender tidbyt.dev/pixlet/encode

build: clean
go build $(LDFLAGS) -o $(BINARY) tidbyt.dev/pixlet
go build $(LDFLAGS) -o $(BINARY) tidbyt.dev/pixlet

embedfonts:
go run render/gen/embedfonts.go
Expand Down
17 changes: 17 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

var Version string

var VersionCmd = &cobra.Command{
Use: "version",
Short: "Show the version of Pixlet",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Pixlet version: %s\n", Version)
},
}
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func init() {
rootCmd.AddCommand(cmd.RenderCmd)
rootCmd.AddCommand(cmd.PushCmd)
rootCmd.AddCommand(cmd.EncryptCmd)
rootCmd.AddCommand(cmd.VersionCmd)
}

func main() {
Expand Down
6 changes: 3 additions & 3 deletions scripts/build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ do
echo "Building ${RELEASE_PLATFORM}_${RELEASE_ARCH}"

if [[ $ARCH == "linux-arm64" ]]; then
CC=aarch64-linux-gnu-gcc CGO_LDFLAGS="-Wl,-Bstatic -lwebp -lwebpdemux -lwebpmux -Wl,-Bdynamic" CGO_ENABLED=1 GOOS=$RELEASE_PLATFORM GOARCH=$RELEASE_ARCH go build -o build/${RELEASE_PLATFORM}_${RELEASE_ARCH}/pixlet tidbyt.dev/pixlet
CC=aarch64-linux-gnu-gcc CGO_LDFLAGS="-Wl,-Bstatic -lwebp -lwebpdemux -lwebpmux -Wl,-Bdynamic" CGO_ENABLED=1 GOOS=$RELEASE_PLATFORM GOARCH=$RELEASE_ARCH go build -ldflags="-X 'tidbyt.dev/pixlet/cmd.Version=${PIXLET_VERSION}'" -o build/${RELEASE_PLATFORM}_${RELEASE_ARCH}/pixlet tidbyt.dev/pixlet
elif [[ $ARCH == "linux-amd64" ]]; then
CGO_LDFLAGS="-Wl,-Bstatic -lwebp -lwebpdemux -lwebpmux -Wl,-Bdynamic" CGO_ENABLED=1 GOOS=$RELEASE_PLATFORM GOARCH=$RELEASE_ARCH go build -o build/${RELEASE_PLATFORM}_${RELEASE_ARCH}/pixlet tidbyt.dev/pixlet
CGO_LDFLAGS="-Wl,-Bstatic -lwebp -lwebpdemux -lwebpmux -Wl,-Bdynamic" CGO_ENABLED=1 GOOS=$RELEASE_PLATFORM GOARCH=$RELEASE_ARCH go build -ldflags="-X 'tidbyt.dev/pixlet/cmd.Version=${PIXLET_VERSION}'" -o build/${RELEASE_PLATFORM}_${RELEASE_ARCH}/pixlet tidbyt.dev/pixlet
else
CGO_CFLAGS="-I/tmp/${LIBWEBP_VERSION}/${ARCH}/include" CGO_LDFLAGS="-L/tmp/${LIBWEBP_VERSION}/${ARCH}/lib" CGO_ENABLED=1 GOOS=$RELEASE_PLATFORM GOARCH=$RELEASE_ARCH go build -o build/${RELEASE_PLATFORM}_${RELEASE_ARCH}/pixlet tidbyt.dev/pixlet
CGO_CFLAGS="-I/tmp/${LIBWEBP_VERSION}/${ARCH}/include" CGO_LDFLAGS="-L/tmp/${LIBWEBP_VERSION}/${ARCH}/lib" CGO_ENABLED=1 GOOS=$RELEASE_PLATFORM GOARCH=$RELEASE_ARCH go build -ldflags="-X 'tidbyt.dev/pixlet/cmd.Version=${PIXLET_VERSION}'" -o build/${RELEASE_PLATFORM}_${RELEASE_ARCH}/pixlet tidbyt.dev/pixlet
fi

echo "Built ./build/${RELEASE_PLATFORM}_${RELEASE_ARCH}/pixlet successfully"
Expand Down

0 comments on commit f61493c

Please sign in to comment.