Добавлен gitea workflow.
All checks were successful
build / build (push) Successful in 1m23s

This commit is contained in:
Алексей Бадяев 2024-10-11 11:45:26 +07:00
parent 6b5f21229c
commit 488c5d649c
Signed by: alexey
GPG Key ID: 686FBC1363E4AFAE
10 changed files with 232 additions and 39 deletions

View File

@ -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

View File

@ -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 <<END
Host $SSH_HOST
IdentitiesOnly yes
User $SSH_USER
IdentityFile ~/.ssh/key
Port $SSH_PORT
StrictHostKeyChecking no
END
cat ~/.ssh/config
make deploy
- name: get meta-data
id: meta
run: |
echo "VERSION=$(make version)" >> $GITHUB_OUTPUT
echo 'CHANGES<<EOF' >> $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

View File

@ -9,8 +9,10 @@
"Badiaev", "Badiaev",
"Childs", "Childs",
"choco", "choco",
"dput",
"drawio", "drawio",
"errcheck", "errcheck",
"gitea",
"gocov", "gocov",
"GOPATH", "GOPATH",
"honnef", "honnef",

View File

@ -1,4 +1,4 @@
drawio-export (1.0) mousesoft-stable; urgency=low drawio-export (VERSION) mousesoft-stable; urgency=low
* Initial Release. * Initial Release.

View File

@ -4,5 +4,5 @@ Maintainer: Aleksei Badiaev <aleksei.badiaev@mousesoft.ru>
Package: drawio-export Package: drawio-export
Section: graphics Section: graphics
Priority: optional Priority: optional
Architecture: amd64 Architecture: ARCH
Description: Export Draw.io diagrams using drawio-desktop. Description: Export Draw.io diagrams using drawio-desktop.

View File

@ -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
}

BIN
drawio-export Executable file

Binary file not shown.

View File

@ -12,7 +12,9 @@ DOC_DIR ?= $(OUTDIR)/doc
VERSION ?= $(strip $(shell ./scripts/version.sh)) VERSION ?= $(strip $(shell ./scripts/version.sh))
VERSION_NUMBER := $(strip $(shell ./scripts/version.sh number)) 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_LDFLAGS ?=
GO_OPT_V := -X "main.version=$(VERSION)" GO_OPT_V := -X "main.version=$(VERSION)"
@ -28,8 +30,8 @@ GOVET := $(GOCMD) vet
ECHO_CMD := echo ECHO_CMD := echo
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
DIST_SUFFIX := windows-$(DIST_KIND) DIST_SUFFIX := windows-$(GOARCH)
MSI_FILE := $(PROJECT_ID)_$(VERSION)_$(DIST_KIND).msi MSI_FILE := $(PROJECT_ID)_$(VERSION)_$(GOARCH).msi
DIST_EXT := .zip DIST_EXT := .zip
DIST_OPTS := -a -cf DIST_OPTS := -a -cf
ECHO_CMD := echo -e ECHO_CMD := echo -e
@ -37,7 +39,7 @@ MSI_VERSION := $(shell echo $(VERSION_NUMBER) | sed -e 's/-.*//')
BIN_SUFFIX := .exe BIN_SUFFIX := .exe
else else
PLATFORM := $(shell uname -s | tr '[:upper:]' '[:lower:]') PLATFORM := $(shell uname -s | tr '[:upper:]' '[:lower:]')
DIST_SUFFIX := $(PLATFORM)-$(DIST_KIND) DIST_SUFFIX := $(GOOS)-$(GOARCH)
DIST_EXT := .tar.gz DIST_EXT := .tar.gz
DIST_OPTS := -czf DIST_OPTS := -czf
endif endif
@ -52,45 +54,52 @@ CYAN := $(shell tput -Txterm setaf 6)
RESET := $(shell tput -Txterm sgr0) RESET := $(shell tput -Txterm sgr0)
.DEFAULT_GOAL := all .DEFAULT_GOAL := all
.PHONY: all version version-number test build dist vendor package pkg-deb
version: ## Version of the project to be built version: ## Version of the project to be built
@echo $(VERSION) @echo $(VERSION)
.PHONY:version
version-number: ## Version number of the project to be built version-number: ## Version number of the project to be built
@echo $(VERSION_NUMBER) @echo $(VERSION_NUMBER)
.PHONY:version-number
## Build: ## Build
all: clean vendor build ## Build binary 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) @mkdir -p $(BINDIR)
@$(ECHO_CMD) "Build\t\t${GREEN}[OK]${RESET}" @$(ECHO_CMD) "Build\t\t${GREEN}[OK]${RESET}"
.PHONY:build
$(BINDIR)/%: cmd/%/main.go $(patsubst cmd/%/main.go,cmd/%/*.go,$<) $(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) \ GO111MODULE=on $(GOCMD) build $(GO_OPT_BASE) $(GO_OPT) \
-o $(BINDIR)/$(BIN_PREFIX)$(patsubst cmd/%/main.go,%,$<)$(BIN_SUFFIX) \ -o "$(BINDIR)/$(BIN_PREFIX)$(patsubst cmd/%/main.go,%,$<)$(BIN_SUFFIX)" \
$(patsubst %/main.go,./%,$<) $(patsubst %/main.go,./%,$<)
dist: ## Create all distro packages dist: build ## Create all distro packages
@rm -f "$(OUTDIR)/$(DIST_FILE)" @rm -f "$(OUTDIR)/$(DIST_FILE)"
tar $(DIST_OPTS) "$(OUTDIR)/$(DIST_FILE)" -C "$(OUTDIR)" bin tar $(DIST_OPTS) "$(OUTDIR)/$(DIST_FILE)" -C "$(OUTDIR)" bin
@$(ECHO_CMD) "Dist\t\t${GREEN}[OK]${RESET}" @$(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 vendor: ## Copy of all packages needed to support builds and tests in the vendor directory
$(GOCMD) mod vendor $(GOCMD) mod vendor
@$(ECHO_CMD) "Vendor\t\t${GREEN}[OK]${RESET}" @$(ECHO_CMD) "Vendor\t\t${GREEN}[OK]${RESET}"
.PHONY:vendor
clean: ## Remove build related files clean: ## Remove build related files
@rm -fr $(TMPDIR) @rm -fr $(TMPDIR)
@rm -fr $(OUTDIR) @rm -fr $(OUTDIR)
@rm -fr dist/ @rm -fr dist/
@$(ECHO_CMD) "Clean\t\t${GREEN}[OK]${RESET}" @$(ECHO_CMD) "Clean\t\t${GREEN}[OK]${RESET}"
.PHONY:clean
## Package: ## Package
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
PACKAGE_TARGETS := pkg-msi PACKAGE_TARGETS := pkg-msi
@ -100,9 +109,11 @@ endif
package: $(PACKAGE_TARGETS) ## Build all available packages package: $(PACKAGE_TARGETS) ## Build all available packages
@$(ECHO_CMD) "Package\t\t${GREEN}[OK]${RESET}" @$(ECHO_CMD) "Package\t\t${GREEN}[OK]${RESET}"
.PHONY:package
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
pkg-msi: ## Create MSI package pkg-msi: dist ## Create MSI package
@rm -rf $(TMPDIR)
@rm -f $(OUTDIR)/$(MSI_FILE) @rm -f $(OUTDIR)/$(MSI_FILE)
@mkdir -p $(TMPDIR) @mkdir -p $(TMPDIR)
go-msi to-rtf --src LICENSE --out $(TMPDIR)/LICENSE.rtf -e go-msi to-rtf --src LICENSE --out $(TMPDIR)/LICENSE.rtf -e
@ -116,29 +127,38 @@ pkg-msi: ## Create MSI package
cd $(TMPDIR) && ./build.bat cd $(TMPDIR) && ./build.bat
mv $(TMPDIR)/$(MSI_FILE) $(OUTDIR)/ mv $(TMPDIR)/$(MSI_FILE) $(OUTDIR)/
@$(ECHO_CMD) "MSI package\t${GREEN}[OK]${RESET}" @$(ECHO_CMD) "MSI package\t${GREEN}[OK]${RESET}"
.PHONY:pkg-msi
else 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)/usr/bin
@mkdir -p $(TMPDIR)/$(DEB_NAME)/debian @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/ @cp -a $(BINDIR)/* $(TMPDIR)/$(DEB_NAME)/usr/bin/
dpkg-gencontrol -v1.0-1 \ @sed -e "s/VERSION/$(VERSION_NUMBER)/g" \
-c$(CURDIR)/build/package/debian/control \ $(CURDIR)/build/package/debian/changelog.tpl \
-lbuild/package/debian/changelog \ > $(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) -f$(TMPDIR)/$(DEB_NAME)/debian/files -Ptmp/$(DEB_NAME)
dpkg-deb --build --root-owner-group $(TMPDIR)/$(DEB_NAME) dpkg-deb --build --root-owner-group $(TMPDIR)/$(DEB_NAME)
dpkg-genchanges --build=binary \ dpkg-genchanges --build=binary \
-c$(CURDIR)/build/package/debian/control \ -c$(TMPDIR)/$(DEB_NAME)/control \
-lbuild/package/debian/changelog \ -l$(TMPDIR)/$(DEB_NAME)/changelog \
-f$(TMPDIR)/$(DEB_NAME)/debian/files \ -f$(TMPDIR)/$(DEB_NAME)/debian/files \
-u$(TMPDIR) -O$(OUTDIR)/$(DEB_NAME).changes -u$(TMPDIR) -O$(OUTDIR)/$(DEB_NAME).changes
@mv $(TMPDIR)/*.deb $(OUTDIR)/ @mv $(TMPDIR)/*.deb $(OUTDIR)/
@$(ECHO_CMD) "pkg-deb\t\t${GREEN}[OK]${RESET}" @$(ECHO_CMD) "pkg-deb\t\t${GREEN}[OK]${RESET}"
.PHONY:pkg-deb
endif endif
## Test: ## Test
test: ## Run the tests of the project test: ## Run the tests of the project
ifeq ($(EXPORT_RESULT), true) ifeq ($(EXPORT_RESULT), true)
@ -147,6 +167,7 @@ ifeq ($(EXPORT_RESULT), true)
endif endif
$(GOTEST) -v $(GO_OPT) ./... $(OUTPUT_OPTIONS) $(GOTEST) -v $(GO_OPT) ./... $(OUTPUT_OPTIONS)
@$(ECHO_CMD) "Test\t\t${GREEN}[OK]${RESET}" @$(ECHO_CMD) "Test\t\t${GREEN}[OK]${RESET}"
.PHONY:test
coverage: ## Run the tests of the project and export the coverage report. coverage: ## Run the tests of the project and export the coverage report.
@mkdir -p out @mkdir -p out
@ -160,28 +181,43 @@ else
endif endif
endif endif
@$(ECHO_CMD) "Coverage\t${GREEN}[OK]${RESET}" @$(ECHO_CMD) "Coverage\t${GREEN}[OK]${RESET}"
.PHONY:coverage
## Lint
## Lint:
lint: lint-go ## Run all available linters. lint: lint-go ## Run all available linters.
@$(ECHO_CMD) "Lint\t\t${GREEN}[OK]${RESET}" @$(ECHO_CMD) "Lint\t\t${GREEN}[OK]${RESET}"
.PHONY:lint
lint-go: lint-go:
go fmt ./... go fmt ./...
go vet ./... go vet ./...
.PHONY:lint-go
## Documentation
## Documentation:
doc: doc-golds ## Generate all documents. doc: doc-golds ## Generate all documents.
@$(ECHO_CMD) "Doc\t\t${GREEN}[OK]${RESET}" @$(ECHO_CMD) "Doc\t\t${GREEN}[OK]${RESET}"
.PHONY:doc
doc-common: doc-common:
@mkdir -p $(DOC_DIR) @mkdir -p $(DOC_DIR)
.PHONY:doc-common
doc-golds: doc-common ## Generate HTML documentation with Golds. doc-golds: doc-common ## Generate HTML documentation with Golds.
@mkdir -p $(DOC_DIR)/html @mkdir -p $(DOC_DIR)/html
golds -gen -dir=$(DOC_DIR)/html -nouses -source-code-reading=rich \ golds -gen -dir=$(DOC_DIR)/html -nouses -source-code-reading=rich \
-silent -only-list-exporteds -wdpkgs-listing=solo ./... -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. help: ## Show this help.
@$(ECHO_CMD) '' @$(ECHO_CMD) ''
@$(ECHO_CMD) 'Usage:' @$(ECHO_CMD) 'Usage:'
@ -192,3 +228,4 @@ help: ## Show this help.
if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${YELLOW}%-20s${GREEN}%s${RESET}\n", $$1, $$2} \ if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${YELLOW}%-20s${GREEN}%s${RESET}\n", $$1, $$2} \
else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \ else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \
}' $(MAKEFILE_LIST) }' $(MAKEFILE_LIST)
.PHONY:help

View File

@ -1,6 +1,6 @@
# Get changes of given version number. # Get changes of given version number.
{ {
while (index($0, "## [" + version + "]") <= 0) { while (index($0, "## [" version "]") <= 0) {
if (getline <= 0) { if (getline <= 0) {
exit exit
} }

View File

@ -1,22 +1,22 @@
#!/bin/bash #!/bin/bash
if [ -z ${TAG_NAME+x} ]; then if [ -z ${TAG_NAME+x} ]; then
if [ -z ${BRANCH_NAME+x} ]; then if [ -z ${BRANCH_NAME+x} ]; then
BRANCH_NAME=$(echo $(git branch --show-current) || \ BRANCH_NAME=$(echo $(git branch --show-current) || \
echo $(git name-rev --name-only HEAD)) echo $(git name-rev --name-only HEAD))
fi fi
GIT_VERSION=$(echo ${BRANCH_NAME} | grep -q 'release/' \ GIT_VERSION=$(echo ${BRANCH_NAME} | grep -q 'release/' \
&& echo ${BRANCH_NAME} | sed -e 's|release/|v|' -e 's/$/-RC/' || \ && echo ${BRANCH_NAME} | sed -e 's|release/|v|' -e 's/$/-RC/' || \
echo $(git describe --always --tags --dirty 2>/dev/null) || echo v0) echo $(git describe --always --tags --dirty 2>/dev/null) || echo v0)
else else
GIT_VERSION=${TAG_NAME} GIT_VERSION=${TAG_NAME}
fi fi
if [ -z ${VERSION+x} ]; then if [ -z ${VERSION+x} ]; then
VERSION=$(echo ${GIT_VERSION} | sed -e 's|^origin/||') VERSION=$(echo ${GIT_VERSION} | sed -e 's|^origin/||')
fi fi
if [ -z $1 ]; then if [ -z $1 ]; then
echo "${VERSION}" echo "${VERSION}"
else else
echo ${VERSION} | sed -e 's/^v//' echo ${VERSION} | sed -e 's/^v//'
fi fi