Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 108 additions & 93 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,104 +10,119 @@ jobs:
build-binary:
name: Build ${{matrix.os}}/${{matrix.arch}} binary
runs-on: ubuntu-latest
strategy:
matrix:
os: ["linux"]
arch: ["amd64", "arm64"]
env:
GOOS: "${{matrix.os}}"
GOARCH: "${{matrix.arch}}"
# strategy:
# matrix:
# os: ["linux"]
# arch: ["amd64", "arm64"]
# env:
# GOOS: "${{matrix.os}}"
# GOARCH: "${{matrix.arch}}"
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: Setup Golang caches
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{runner.os}}-golang-${{matrix.os}}_${{matrix.arch}}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{runner.os}}-golang-${{matrix.os}}_${{matrix.arch}}-

- name: Vet
run: go vet -v ./...

- name: Test
run: go test -v ./...

- name: Build
run: go build -v -o 'bin/semver-tagger_${{matrix.os}}_${{matrix.arch}}' main.go

- uses: actions/upload-artifact@v3
with:
name: bin
path: bin/

publish-binaries:
name: Publish binaries to release
if: github.event_name == 'release'
runs-on: ubuntu-latest
needs: build-binary
steps:
- uses: actions/download-artifact@v3
with:
name: bin
path: bin

- name: Upload binaries to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: bin/*
file_glob: true
overwrite: true

build-and-push-image:
name: Build image and push to repository
runs-on: ubuntu-latest
needs: build-binary
steps:
- name: Checkout
uses: actions/checkout@v3

- uses: actions/download-artifact@v3
with:
name: bin
path: bin

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/vflaux/semver-tagger
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=sha

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build image
uses: docker/build-push-action@v3
- run: echo $HOME
- run: cat $HOME/.docker/config.json
- uses: vflaux/semver-tagger-action@v1
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
image: ghcr.io/vflaux/semver-tagger-action:0.1.1



# - uses: actions/checkout@v3

# - name: Set up Go
# uses: actions/setup-go@v3
# with:
# go-version: 1.19

# - name: Setup Golang caches
# uses: actions/cache@v3
# with:
# path: |
# ~/.cache/go-build
# ~/go/pkg/mod
# key: ${{runner.os}}-golang-${{matrix.os}}_${{matrix.arch}}-${{ hashFiles('**/go.sum') }}
# restore-keys: |
# ${{runner.os}}-golang-${{matrix.os}}_${{matrix.arch}}-

# - name: Vet
# run: go vet -v ./...

# - name: Test
# run: go test -v ./...

# - name: Build
# run: go build -v -o 'bin/semver-tagger_${{matrix.os}}_${{matrix.arch}}' main.go

# - uses: actions/upload-artifact@v3
# with:
# name: bin
# path: bin/

# publish-binaries:
# name: Publish binaries to release
# if: github.event_name == 'release'
# runs-on: ubuntu-latest
# needs: build-binary
# steps:
# - uses: actions/download-artifact@v3
# with:
# name: bin
# path: bin

# - name: Upload binaries to release
# uses: svenstaro/upload-release-action@v2
# with:
# repo_token: ${{ secrets.GITHUB_TOKEN }}
# file: bin/*
# file_glob: true
# overwrite: true

# build-and-push-image:
# name: Build image and push to repository
# runs-on: ubuntu-latest
# needs: build-binary
# steps:
# - name: Checkout
# uses: actions/checkout@v3

# - uses: actions/download-artifact@v3
# with:
# name: bin
# path: bin

# - name: Docker meta
# id: meta
# uses: docker/metadata-action@v4
# with:
# images: ghcr.io/vflaux/semver-tagger
# flavor: |
# latest=false
# tags: |
# type=semver,pattern={{version}}
# type=sha
# labels: |
# org.opencontainers.image.description=A tool to remotely tag an image if it is the latest version

# - name: Login to GitHub Container Registry
# uses: docker/login-action@v2
# with:
# registry: ghcr.io
# username: ${{ github.repository_owner }}
# password: ${{ secrets.GITHUB_TOKEN }}

# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v2

# - name: Build image
# uses: docker/build-push-action@v3
# with:
# context: .
# push: ${{ github.event_name != 'pull_request' }}
# platforms: linux/amd64,linux/arm64
# tags: ${{ steps.meta.outputs.tags }}
# labels: ${{ steps.meta.outputs.labels }}
35 changes: 15 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
ARG ALPINE_VERSION=3.17

FROM alpine:${ALPINE_VERSION}

RUN apk add make --no-cache
# syntax=docker.io/docker/dockerfile:1.4

FROM scratch as base
ARG TARGETOS
ARG TARGETARCH

COPY bin/semver-tagger_${TARGETOS}_${TARGETARCH} /usr/local/bin/semver-tagger
ENTRYPOINT ["/usr/local/bin/semver-tagger"]

FROM debian:bookworm-slim as debian
ARG TARGETOS
ARG TARGETARCH
COPY --link bin/semver-tagger_${TARGETOS}_${TARGETARCH} /usr/local/bin/semver-tagger

ARG VENDOR
ARG SOURCE
ARG VERSION
ARG REVISION
ARG TITLE
ARG CREATED
FROM debian as github-action
COPY --link semver-tagger-action/entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

LABEL \
org.opencontainers.image.description="A tool to remotely tag an image if it is the latest version" \
org.opencontainers.image.vendor="$VENDOR" \
org.opencontainers.image.source="$SOURCE" \
org.opencontainers.image.version="$VERSION" \
org.opencontainers.image.revision="$REVISION" \
org.opencontainers.image.title="$TITLE" \
org.opencontainers.image.created="$CREATED"
FROM alpine:3.17 as alpine
ARG TARGETOS
ARG TARGETARCH
COPY --link bin/semver-tagger_${TARGETOS}_${TARGETARCH} /usr/local/bin/semver-tagger