diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ccf27cc --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,20 @@ +name: Actions +on: + push: + branches: + - "*" + tags-ignore: + - "v*" + pull_request: {} + workflow_dispatch: {} +jobs: + build: + name: Build + runs-on: ubuntu-latest + strategy: + matrix: + platform: [amd64] + steps: + - uses: actions/checkout@v4 + - name: Build linux/${{ matrix.platform }} + run: make images -j$(nproc) GOOS=linux GOARCH=${{ matrix.platform }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..020c6f9 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,21 @@ +name: Release +on: + push: + branches: + - "main" + workflow_dispatch: {} +jobs: + build: + name: Build + runs-on: ubuntu-latest + strategy: + matrix: + platform: [amd64] + steps: + - uses: actions/checkout@v4 + + - name: Build linux/${{ matrix.platform }} + run: make images -j $(nproc) GOOS=linux GOARCH=${{ matrix.platform }} + + - name: Push linux/${{ matrix.platform }} + run: make push -j $(nprox) diff --git a/lint.mk b/Lint.mk similarity index 100% rename from lint.mk rename to Lint.mk diff --git a/Makefile b/Makefile index b4ab822..284d6b2 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,52 @@ -BINS = archive2disk cexec grub2disk kexec oci2disk qemuimg2disk rootio slurp syslinux writefile +# Use bash +SHELL := bash +.SHELLFLAGS := -o pipefail -euc +.ONESHELL: -include rules.mk +# Second expansion is used by the image targets to depend on their respective binaries. It is +# necessary because automatic variables are not set on first expansion. +# See https://www.gnu.org/software/make/manual/html_node/Secondary-Expansion.html. +.SECONDEXPANSION: -all: $(BINS) +# Define the list of actions that can be built. +ACTIONS := archive2disk cexec grub2disk kexec oci2disk qemuimg2disk rootio slurp syslinux writefile -.PHONY: $(BINS) -$(BINS): +# Define the commit for tagging images. +GIT_COMMIT := $(shell git rev-parse HEAD) + +# Define Docker registry details. +DOCKER_REPOSITORY := quay.io/tinkerbell/actions + +include Rules.mk + +.PHONY: help +help: ## Print this help + @awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m\033[0m\n"} /^[%\/0-9A-Za-z_-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) + @echo + @echo Individual actions can be built with their name. For example, \`make archive2disk\`. + + +.PHONY: $(ACTIONS) +$(ACTIONS): ## Build a specific action image. docker buildx build --platform linux/amd64 --load -t $@:latest -f ./$@/Dockerfile . +.PHONY: images +images: ## Build all action images. +images: $(ACTIONS) + +.PHONY: push +push: ## Push all action images. +push: $(addprefix push-,$(ACTIONS)) + +.PHONY: push-% +push-%: ## Push a specific action image to the registry. This recipe assumes you are already authenticated with the registry. + IMAGE_NAME=$(DOCKER_REPOSITORY)/$*:$(GIT_COMMIT) + docker tag $*:latest $$IMAGE_NAME + docker push $$IMAGE_NAME + +formatters: ## Run all formatters. formatters: $(toolBins) git ls-files '*.go' | xargs -I% sh -c 'sed -i "/^import (/,/^)/ { /^\s*$$/ d }" % && bin/gofumpt -w %' git ls-files '*.go' | xargs -I% bin/goimports -w % -tidy-all: - for d in $(BINS); do (cd $$d; go mod tidy); done - -include lint.mk +include Lint.mk diff --git a/rules.mk b/Rules.mk similarity index 100% rename from rules.mk rename to Rules.mk diff --git a/archive2disk/main.go b/archive2disk/main.go index 90043f5..739b866 100644 --- a/archive2disk/main.go +++ b/archive2disk/main.go @@ -8,7 +8,7 @@ import ( "syscall" log "github.com/sirupsen/logrus" - "github.com/tinkerbell/hub/archive2disk/archive" + "github.com/tinkerbell/actions/archive2disk/archive" ) const mountAction = "/mountAction" diff --git a/grub2disk/main.go b/grub2disk/main.go index 3b1fec9..31b74e3 100644 --- a/grub2disk/main.go +++ b/grub2disk/main.go @@ -6,7 +6,7 @@ import ( "os/exec" log "github.com/sirupsen/logrus" - "github.com/tinkerbell/hub/grub2disk/grub" + "github.com/tinkerbell/actions/grub2disk/grub" ) func main() { diff --git a/image2disk/main.go b/image2disk/main.go index d9f1c27..eefb575 100644 --- a/image2disk/main.go +++ b/image2disk/main.go @@ -6,7 +6,7 @@ import ( "strconv" log "github.com/sirupsen/logrus" - "github.com/tinkerbell/hub/image2disk/image" + "github.com/tinkerbell/actions/image2disk/image" ) func main() { diff --git a/kexec/cmd/kexec.go b/kexec/cmd/kexec.go index f92ab4e..ba6e598 100644 --- a/kexec/cmd/kexec.go +++ b/kexec/cmd/kexec.go @@ -9,7 +9,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/spf13/cobra" - "github.com/tinkerbell/hub/kexec/cmd/grub" + "github.com/tinkerbell/actions/kexec/cmd/grub" "golang.org/x/sys/unix" ) diff --git a/kexec/main.go b/kexec/main.go index 770608d..d6870b7 100644 --- a/kexec/main.go +++ b/kexec/main.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/tinkerbell/hub/kexec/cmd" + "github.com/tinkerbell/actions/kexec/cmd" ) func main() { diff --git a/oci2disk/main.go b/oci2disk/main.go index e536094..b5de114 100644 --- a/oci2disk/main.go +++ b/oci2disk/main.go @@ -6,7 +6,7 @@ import ( "strconv" log "github.com/sirupsen/logrus" - "github.com/tinkerbell/hub/oci2disk/image" + "github.com/tinkerbell/actions/oci2disk/image" ) func main() { diff --git a/rootio/cmd/rootio.go b/rootio/cmd/rootio.go index d39320f..825adfb 100644 --- a/rootio/cmd/rootio.go +++ b/rootio/cmd/rootio.go @@ -8,7 +8,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/spf13/cobra" - "github.com/tinkerbell/hub/rootio/storage" + "github.com/tinkerbell/actions/rootio/storage" ) var metadata *storage.Metadata diff --git a/rootio/main.go b/rootio/main.go index 12a3e81..878a9af 100644 --- a/rootio/main.go +++ b/rootio/main.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/tinkerbell/hub/rootio/cmd" + "github.com/tinkerbell/actions/rootio/cmd" ) func main() { diff --git a/rootio/storage/lvm.go b/rootio/storage/lvm.go index aa34d1e..3979336 100644 --- a/rootio/storage/lvm.go +++ b/rootio/storage/lvm.go @@ -3,7 +3,7 @@ package storage import ( "fmt" - "github.com/tinkerbell/hub/rootio/lvm" + "github.com/tinkerbell/actions/rootio/lvm" ) func CreateVolumeGroup(volumeGroup VolumeGroup) error { diff --git a/slurp/main.go b/slurp/main.go index e2209e8..20abaf6 100644 --- a/slurp/main.go +++ b/slurp/main.go @@ -6,7 +6,7 @@ import ( "strconv" log "github.com/sirupsen/logrus" - "github.com/tinkerbell/hub/slurp/image" + "github.com/tinkerbell/actions/slurp/image" ) func main() {