diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..6f51382 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,46 @@ +default: + image: debian:11 + +stages: + - build + - publish + - release + +build: + stage: build + image: golang:1.21-alpine + before_script: + - apk update && apk add --no-cache make git + script: + - make build_password + artifacts: + paths: + - ./bin/* + +publish_main: + stage: publish + image: golang:1.21-alpine + variables: + VER: latest + before_script: + - apk update && apk add --no-cache make git curl + script: + - make publish_password + needs: + - build + only: + - main + +release_tag: + stage: publish + image: golang:1.21-alpine + variables: + VER: ${CI_COMMIT_TAG} + before_script: + - apk update && apk add --no-cache make git curl + script: + - make publish_password + needs: + - build + only: + - tags \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8a6bf90 --- /dev/null +++ b/Makefile @@ -0,0 +1,28 @@ +ARCH := amd64 arm64 +OS := linux windows darwin +NAME := password +VERSION := $(shell git describe) +BUILD := $(shell git rev-parse HEAD) + +LDFLAGS=-ldflags "-X main.Version=${VERSION} -X main.Build=${BUILD}" + +.PHONY: all build + +all: build + +build_password: + $(foreach GOOS, ${OS},\ + $(foreach GOARCH, ${ARCH}, \ + $(shell CGO_ENABLED=0 go build -v -o bin/${NAME} ./golang/cmd/passwordhash;cd bin/;[ "${GOOS}" = "windows" ] && mv ${NAME} ${NAME}.exe;tar czf ${NAME}_${GOOS}_${GOARCH}.tar.gz *;rm -f ${NAME} ${NAME}.exe) \ + )) + +publish_password: + $(foreach GOOS, ${OS},\ + $(foreach GOARCH, ${ARCH}, \ + $(curl --silent --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file bin/${NAME}_${GOOS}_${GOARCH}.tar.gz "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${NAME}/${VER}/${NAME}_${GOOS}_${GOARCH}.tar.gz") \ + )) + +clean: + rm -rf bin + +re: clean all \ No newline at end of file