diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml new file mode 100644 index 0000000..5421bd5 --- /dev/null +++ b/.gitea/workflows/build.yaml @@ -0,0 +1,57 @@ +name: build + +run-name: ${{ gitea.actor }} build MouseSoft Draw.IO Export + +on: + push: + branches: + - "**" + +jobs: + build: + runs-on: ubuntu-latest + # container: + # image: git.mousesoft.ru/ms/gitea-runner-images:python-ubuntu-latest + steps: + - name: check-out repository code + uses: https://gitea.com/actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true + + - name: set-up go + uses: https://gitea.com/actions/setup-go@v3 + with: + go-version: ">=1.22" + + - name: test + run: make clean vendor lint test + + - name: cache + uses: https://gitea.com/actions/cache@v4 + with: + path: | + out/*.tar.gz + key: ms_drawio-export_${{ github.sha }} + + - name: build amd64 binary + if: steps.cache.outputs.cache-hit != 'true' + run: GOARCH=amd64 make dist + + - name: upload amd64 binary + uses: https://gitea.com/actions/upload-artifact@v3 + with: + name: drawio-export-amd64 + path: out/dist/*-amd64.tar.gz + overwrite: true + + - name: build arm64 binary + if: steps.cache.outputs.cache-hit != 'true' + run: GOARCH=arm64 make dist + + - name: upload arm64 binary + uses: https://gitea.com/actions/upload-artifact@v3 + with: + name: drawio-export-arm64 + path: out/dist/*-arm64.tar.gz + overwrite: true diff --git a/.gitea/workflows/release.yaml b/.gitea/workflows/release.yaml new file mode 100644 index 0000000..839e884 --- /dev/null +++ b/.gitea/workflows/release.yaml @@ -0,0 +1,85 @@ +name: release + +run-name: ${{ gitea.actor }} release MouseSoft Draw.IO Export + +on: + push: + tags: + - "v*" + +jobs: + release: + runs-on: ubuntu-latest + # container: + # image: git.mousesoft.ru/ms/gitea-runner-images:python-ubuntu-latest + steps: + - name: check-out repository code + uses: https://gitea.com/actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true + + - name: set-up go + uses: https://gitea.com/actions/setup-go@v3 + with: + go-version: ">=1.22" + + - name: test + run: make clean vendor lint test + + - name: cache + uses: https://gitea.com/actions/cache@v4 + with: + path: | + out/*.deb + out/*.changes + key: ms_drawio-export_pkg_${{ github.sha }} + + - name: build amd64 package + if: steps.cache.outputs.cache-hit != 'true' + run: GOARCH=amd64 make package + + - name: build arm64 package + if: steps.cache.outputs.cache-hit != 'true' + run: GOARCH=arm64 make package + + - name: deploy packages + env: + SSH_HOST: ${{ secrets.DEB_SSH_HOST }} + SSH_PORT: ${{ secrets.DEB_SSH_PORT }} + SSH_USER: ${{ secrets.DEB_SSH_USER }} + SSH_KEY: ${{ secrets.DEB_SSH_KEY }} + run: | + sed -e "s/DEB_SSH_HOST/$SSH_HOST/g" deploy/dput/mousesoft.json.tpl > /etc/dput.d/profiles/mousesoft.json + mkdir -p ~/.ssh/ + echo "$SSH_KEY" | tr -d '\r' > ~/.ssh/key + chmod 0600 ~/.ssh/key + cat >>~/.ssh/config <> $GITHUB_OUTPUT + echo 'CHANGES<> $GITHUB_OUTPUT + gawk -f scripts/changes.awk -v version=$(make version-number) CHANGELOG.md >> $GITHUB_OUTPUT + echo EOF >> $GITHUB_OUTPUT + + - name: release + uses: https://gitea.com/actions/gitea-release-action@v1 + with: + title: "MouseSoft DrawIO-Export ${{ steps.meta.outputs.VERSION }}" + body: "${{ steps.meta.outputs.CHANGES }}" + files: | + out/*.deb + sha256sum: true + prerelease: true + draft: true diff --git a/.vscode/settings.json b/.vscode/settings.json index c4e7e43..a17d137 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,8 +9,10 @@ "Badiaev", "Childs", "choco", + "dput", "drawio", "errcheck", + "gitea", "gocov", "GOPATH", "honnef", diff --git a/build/package/debian/changelog b/build/package/debian/changelog.tpl similarity index 66% rename from build/package/debian/changelog rename to build/package/debian/changelog.tpl index ef49c4a..532b298 100644 --- a/build/package/debian/changelog +++ b/build/package/debian/changelog.tpl @@ -1,4 +1,4 @@ -drawio-export (1.0) mousesoft-stable; urgency=low +drawio-export (VERSION) mousesoft-stable; urgency=low * Initial Release. diff --git a/build/package/debian/control b/build/package/debian/control.tpl similarity index 90% rename from build/package/debian/control rename to build/package/debian/control.tpl index 2d1b935..6304d30 100644 --- a/build/package/debian/control +++ b/build/package/debian/control.tpl @@ -4,5 +4,5 @@ Maintainer: Aleksei Badiaev Package: drawio-export Section: graphics Priority: optional -Architecture: amd64 +Architecture: ARCH Description: Export Draw.io diagrams using drawio-desktop. diff --git a/deploy/dput/mousesoft.json.tpl b/deploy/dput/mousesoft.json.tpl new file mode 100644 index 0000000..634a01e --- /dev/null +++ b/deploy/dput/mousesoft.json.tpl @@ -0,0 +1,12 @@ +{ + "allow_unsigned_uploads": true, + "full_upload_log": false, + "fqdn": "DEB_SSH_HOST", + "hash": "sha1", + "interface": "cli", + "incoming": "mini-dinstall/incoming/", + "login": "mini-dinstall", + "meta": "boring", + "method": "scp", + "scp_compress": true +} \ No newline at end of file diff --git a/drawio-export b/drawio-export new file mode 100755 index 0000000..ad7c142 Binary files /dev/null and b/drawio-export differ diff --git a/makefile b/makefile index d5023bf..d756c48 100644 --- a/makefile +++ b/makefile @@ -12,7 +12,9 @@ DOC_DIR ?= $(OUTDIR)/doc VERSION ?= $(strip $(shell ./scripts/version.sh)) VERSION_NUMBER := $(strip $(shell ./scripts/version.sh number)) -DIST_KIND := $(shell uname -m) + +GOARCH ?= $(shell go env GOARCH) +GOOS ?= $(shell go env GOOS) GO_LDFLAGS ?= GO_OPT_V := -X "main.version=$(VERSION)" @@ -28,8 +30,8 @@ GOVET := $(GOCMD) vet ECHO_CMD := echo ifeq ($(OS),Windows_NT) -DIST_SUFFIX := windows-$(DIST_KIND) -MSI_FILE := $(PROJECT_ID)_$(VERSION)_$(DIST_KIND).msi +DIST_SUFFIX := windows-$(GOARCH) +MSI_FILE := $(PROJECT_ID)_$(VERSION)_$(GOARCH).msi DIST_EXT := .zip DIST_OPTS := -a -cf ECHO_CMD := echo -e @@ -37,7 +39,7 @@ MSI_VERSION := $(shell echo $(VERSION_NUMBER) | sed -e 's/-.*//') BIN_SUFFIX := .exe else PLATFORM := $(shell uname -s | tr '[:upper:]' '[:lower:]') -DIST_SUFFIX := $(PLATFORM)-$(DIST_KIND) +DIST_SUFFIX := $(GOOS)-$(GOARCH) DIST_EXT := .tar.gz DIST_OPTS := -czf endif @@ -52,45 +54,52 @@ CYAN := $(shell tput -Txterm setaf 6) RESET := $(shell tput -Txterm sgr0) .DEFAULT_GOAL := all -.PHONY: all version version-number test build dist vendor package pkg-deb version: ## Version of the project to be built @echo $(VERSION) +.PHONY:version version-number: ## Version number of the project to be built @echo $(VERSION_NUMBER) +.PHONY:version-number -## Build: +## Build all: clean vendor build ## Build binary +.PHONY:all -APPS = $(patsubst cmd/%/, %, $(dir $(wildcard cmd/*/main.go))) +APPS := $(patsubst cmd/%/, %, $(dir $(wildcard cmd/*/main.go))) -build: $(addprefix $(BINDIR)/, $(APPS)) ## Build your project and put the output binary in out/bin/ +build: vendor $(addprefix $(BINDIR)/, $(APPS)) ## Build your project and put the output binary in out/bin/ @mkdir -p $(BINDIR) @$(ECHO_CMD) "Build\t\t${GREEN}[OK]${RESET}" +.PHONY:build $(BINDIR)/%: cmd/%/main.go $(patsubst cmd/%/main.go,cmd/%/*.go,$<) + @rm -f "$(BINDIR)/$(BIN_PREFIX)$(patsubst cmd/%/main.go,%,$<)$(BIN_SUFFIX)" GO111MODULE=on $(GOCMD) build $(GO_OPT_BASE) $(GO_OPT) \ - -o $(BINDIR)/$(BIN_PREFIX)$(patsubst cmd/%/main.go,%,$<)$(BIN_SUFFIX) \ - $(patsubst %/main.go,./%,$<) + -o "$(BINDIR)/$(BIN_PREFIX)$(patsubst cmd/%/main.go,%,$<)$(BIN_SUFFIX)" \ + $(patsubst %/main.go,./%,$<) -dist: ## Create all distro packages +dist: build ## Create all distro packages @rm -f "$(OUTDIR)/$(DIST_FILE)" tar $(DIST_OPTS) "$(OUTDIR)/$(DIST_FILE)" -C "$(OUTDIR)" bin @$(ECHO_CMD) "Dist\t\t${GREEN}[OK]${RESET}" +.PHONY:dist vendor: ## Copy of all packages needed to support builds and tests in the vendor directory $(GOCMD) mod vendor @$(ECHO_CMD) "Vendor\t\t${GREEN}[OK]${RESET}" +.PHONY:vendor clean: ## Remove build related files @rm -fr $(TMPDIR) @rm -fr $(OUTDIR) @rm -fr dist/ @$(ECHO_CMD) "Clean\t\t${GREEN}[OK]${RESET}" +.PHONY:clean -## Package: +## Package ifeq ($(OS),Windows_NT) PACKAGE_TARGETS := pkg-msi @@ -100,9 +109,11 @@ endif package: $(PACKAGE_TARGETS) ## Build all available packages @$(ECHO_CMD) "Package\t\t${GREEN}[OK]${RESET}" +.PHONY:package ifeq ($(OS),Windows_NT) -pkg-msi: ## Create MSI package +pkg-msi: dist ## Create MSI package + @rm -rf $(TMPDIR) @rm -f $(OUTDIR)/$(MSI_FILE) @mkdir -p $(TMPDIR) go-msi to-rtf --src LICENSE --out $(TMPDIR)/LICENSE.rtf -e @@ -116,29 +127,38 @@ pkg-msi: ## Create MSI package cd $(TMPDIR) && ./build.bat mv $(TMPDIR)/$(MSI_FILE) $(OUTDIR)/ @$(ECHO_CMD) "MSI package\t${GREEN}[OK]${RESET}" +.PHONY:pkg-msi else -DEB_NAME := $(PROJECT_ID)_$(VERSION_NUMBER)-1_amd64 -pkg-deb: ## Build debian package +DEB_NAME := $(PROJECT_ID)_$(VERSION_NUMBER)-1_$(GOARCH) + +pkg-deb: dist ## Build debian package + @rm -rf $(TMPDIR) @mkdir -p $(TMPDIR)/$(DEB_NAME)/usr/bin - @mkdir -p $(TMPDIR)/$(DEB_NAME)/debian + @mkdir -p $(TMPDIR)/$(DEB_NAME)/debian @mkdir -p $(TMPDIR)/$(DEB_NAME)/DEBIAN @cp -a $(BINDIR)/* $(TMPDIR)/$(DEB_NAME)/usr/bin/ - dpkg-gencontrol -v1.0-1 \ - -c$(CURDIR)/build/package/debian/control \ - -lbuild/package/debian/changelog \ + @sed -e "s/VERSION/$(VERSION_NUMBER)/g" \ + $(CURDIR)/build/package/debian/changelog.tpl \ + > $(TMPDIR)/$(DEB_NAME)/changelog + @sed -e "s/ARCH/$(GOARCH)/g" $(CURDIR)/build/package/debian/control.tpl \ + > $(TMPDIR)/$(DEB_NAME)/control + DEB_HOST_ARCH=$(GOARCH) dpkg-gencontrol -v$(VERSION_NUMBER)-1 \ + -c$(TMPDIR)/$(DEB_NAME)/control \ + -l$(TMPDIR)/$(DEB_NAME)/changelog \ -f$(TMPDIR)/$(DEB_NAME)/debian/files -Ptmp/$(DEB_NAME) dpkg-deb --build --root-owner-group $(TMPDIR)/$(DEB_NAME) dpkg-genchanges --build=binary \ - -c$(CURDIR)/build/package/debian/control \ - -lbuild/package/debian/changelog \ + -c$(TMPDIR)/$(DEB_NAME)/control \ + -l$(TMPDIR)/$(DEB_NAME)/changelog \ -f$(TMPDIR)/$(DEB_NAME)/debian/files \ -u$(TMPDIR) -O$(OUTDIR)/$(DEB_NAME).changes @mv $(TMPDIR)/*.deb $(OUTDIR)/ @$(ECHO_CMD) "pkg-deb\t\t${GREEN}[OK]${RESET}" +.PHONY:pkg-deb endif -## Test: +## Test test: ## Run the tests of the project ifeq ($(EXPORT_RESULT), true) @@ -147,6 +167,7 @@ ifeq ($(EXPORT_RESULT), true) endif $(GOTEST) -v $(GO_OPT) ./... $(OUTPUT_OPTIONS) @$(ECHO_CMD) "Test\t\t${GREEN}[OK]${RESET}" +.PHONY:test coverage: ## Run the tests of the project and export the coverage report. @mkdir -p out @@ -160,28 +181,43 @@ else endif endif @$(ECHO_CMD) "Coverage\t${GREEN}[OK]${RESET}" +.PHONY:coverage + +## Lint -## Lint: lint: lint-go ## Run all available linters. @$(ECHO_CMD) "Lint\t\t${GREEN}[OK]${RESET}" +.PHONY:lint lint-go: go fmt ./... go vet ./... +.PHONY:lint-go + +## Documentation -## Documentation: doc: doc-golds ## Generate all documents. @$(ECHO_CMD) "Doc\t\t${GREEN}[OK]${RESET}" +.PHONY:doc doc-common: @mkdir -p $(DOC_DIR) +.PHONY:doc-common doc-golds: doc-common ## Generate HTML documentation with Golds. @mkdir -p $(DOC_DIR)/html golds -gen -dir=$(DOC_DIR)/html -nouses -source-code-reading=rich \ -silent -only-list-exporteds -wdpkgs-listing=solo ./... +.PHONY:doc-golds + +## Deploy + +deploy: ## deploy debian packages + find -O1 $(OUT_DIR) -name '*.changes' -exec dput mousesoft \{\} \; +.PHONY:deploy-deb + +## Help -## Help: help: ## Show this help. @$(ECHO_CMD) '' @$(ECHO_CMD) 'Usage:' @@ -192,3 +228,4 @@ help: ## Show this help. if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${YELLOW}%-20s${GREEN}%s${RESET}\n", $$1, $$2} \ else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \ }' $(MAKEFILE_LIST) +.PHONY:help diff --git a/scripts/changes.awk b/scripts/changes.awk index 8441a80..4c8e834 100644 --- a/scripts/changes.awk +++ b/scripts/changes.awk @@ -1,6 +1,6 @@ # Get changes of given version number. { - while (index($0, "## [" + version + "]") <= 0) { + while (index($0, "## [" version "]") <= 0) { if (getline <= 0) { exit } diff --git a/scripts/version.sh b/scripts/version.sh index d0426f4..7f922b2 100755 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -1,22 +1,22 @@ #!/bin/bash if [ -z ${TAG_NAME+x} ]; then -if [ -z ${BRANCH_NAME+x} ]; then -BRANCH_NAME=$(echo $(git branch --show-current) || \ - echo $(git name-rev --name-only HEAD)) -fi -GIT_VERSION=$(echo ${BRANCH_NAME} | grep -q 'release/' \ - && echo ${BRANCH_NAME} | sed -e 's|release/|v|' -e 's/$/-RC/' || \ - echo $(git describe --always --tags --dirty 2>/dev/null) || echo v0) + if [ -z ${BRANCH_NAME+x} ]; then + BRANCH_NAME=$(echo $(git branch --show-current) || \ + echo $(git name-rev --name-only HEAD)) + fi + GIT_VERSION=$(echo ${BRANCH_NAME} | grep -q 'release/' \ + && echo ${BRANCH_NAME} | sed -e 's|release/|v|' -e 's/$/-RC/' || \ + echo $(git describe --always --tags --dirty 2>/dev/null) || echo v0) else -GIT_VERSION=${TAG_NAME} + GIT_VERSION=${TAG_NAME} fi if [ -z ${VERSION+x} ]; then -VERSION=$(echo ${GIT_VERSION} | sed -e 's|^origin/||') + VERSION=$(echo ${GIT_VERSION} | sed -e 's|^origin/||') fi if [ -z $1 ]; then -echo "${VERSION}" + echo "${VERSION}" else -echo ${VERSION} | sed -e 's/^v//' + echo ${VERSION} | sed -e 's/^v//' fi