From ec6351ec91f3ca396dd1aed79b6ca8d5b3811877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9=20=D0=91=D0=B0?= =?UTF-8?q?=D0=B4=D1=8F=D0=B5=D0=B2?= Date: Tue, 4 Apr 2023 19:46:25 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=20=D0=BA?= =?UTF-8?q?=D0=B0=D1=80=D0=BA=D0=B0=D1=81=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=B0=20=D0=B8=20=D1=81=D0=B8=D1=81=D1=82=D0=B5=D0=BC?= =?UTF-8?q?=D0=B0=20=D1=81=D0=B1=D0=BE=D1=80=D0=BA=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 5 + .vscode/tasks.json | 107 +++++++++++++++++++ CHANGELOG.md | 11 ++ README.md | 4 +- build/ci/Jenkinsfile | 214 ++++++++++++++++++++++++++++++++++++++ cmd/drawio-export/main.go | 7 ++ go.mod | 3 + makefile | 136 ++++++++++++++++++++++++ scripts/changes.awk | 20 ++++ scripts/version.sh | 22 ++++ 10 files changed, 528 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json create mode 100644 CHANGELOG.md create mode 100644 build/ci/Jenkinsfile create mode 100644 cmd/drawio-export/main.go create mode 100644 go.mod create mode 100644 makefile create mode 100644 scripts/changes.awk create mode 100755 scripts/version.sh diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ba29104 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "cSpell.words": [ + "drawio" + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..de4cb3b --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,107 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "type": "shell", + "command": "make vendor build", + "group": "build", + "icon": { + "id": "briefcase", + "color": "terminal.ansiGreen" + } + }, + { + "label": "dist", + "type": "shell", + "command": "make build dist", + "group": "build", + "icon": { + "id": "briefcase", + "color": "terminal.ansiBlue" + }, + "options": { + "env": { + "GO_OPT": "" + } + } + }, + { + "label": "doc HTML", + "type": "shell", + "command": "make doc", + "group": "build", + "icon": { + "id": "book", + "color": "terminal.ansiBlue" + }, + "options": { + "env": { + "DOC_FORMAT": "html" + } + } + }, + { + "label": "doc PDF", + "type": "shell", + "command": "make doc", + "group": "build", + "icon": { + "id": "book", + "color": "terminal.ansiRed" + }, + "options": { + "env": { + "DOC_FORMAT": "pdf" + } + } + }, + { + "label": "test", + "type": "shell", + "command": "make test", + "group": "test", + "icon": { + "id": "beaker", + "color": "terminal.ansiGreen" + } + }, + { + "label": "coverage", + "type": "shell", + "command": "make coverage", + "group": "test", + "icon": { + "id": "beaker", + "color": "terminal.ansiGreen" + } + }, + { + "label": "coverage HTML", + "type": "shell", + "command": "make coverage", + "group": "test", + "icon": { + "id": "beaker", + "color": "terminal.ansiBlue" + }, + "options": { + "env": { + "EXPORT_RESULT": "true" + } + } + }, + { + "label": "clean", + "type": "shell", + "command": "make clean", + "group": "build", + "icon": { + "id": "trash", + "color": "terminal.ansiBlack" + } + } + ] +} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..dcd562a --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +# Changelog + +Все заметные изменения в этом проекте будут документироваться в этом файле. +Формат основан на [Keep a Changelog](https://keepachangelog.com/ru/1.1.0/), +и этот проект придерживается [Semantic Versioning](https://semver.org/lang/ru/). + +## [0.1] - Не опубликовано + +- **Добавлено** + - Все параметры передаются программе `drawio` из пакета `drawio-desktop` без + изменений. diff --git a/README.md b/README.md index f0b3e22..7ec9dc2 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ -# drawio-exporter +# Go Draw.io Exporter +Экспортирует все диаграммы из файла формата `Draw.io`. +Для работы необходимо наличие приложения `drawio-desktop`. diff --git a/build/ci/Jenkinsfile b/build/ci/Jenkinsfile new file mode 100644 index 0000000..8007918 --- /dev/null +++ b/build/ci/Jenkinsfile @@ -0,0 +1,214 @@ +// MouseSoft Ships Jenkins declarative pipeline + +pipeline { + agent { label 'go' } + options { + ansiColor('css') + timestamps() + buildDiscarder(logRotator(numToKeepStr: '10')) + skipDefaultCheckout() + timeout(time: 8, unit: 'MINUTES', activity: true) + } + environment { + PROJECT_OWNER = 'ms' + PROJECT_ID = 'drawio-exporter' + PROJECT_NAME = 'MouseSoft Draw.io Exporter' + ROCKET_TITLE = "${currentBuild.fullDisplayName} (<${env.BUILD_URL}|Open>)" + RELEASE_ID = 0 + } + stages { + stage('Build') { + parallel { + stage('Build Linux') { + steps { + echo "***** BUILD ${PROJECT_NAME} on Linux *****" + msSendRocketChat("${ROCKET_TITLE}", msBuildInfo(currentBuild), 'black') + cleanWs(disableDeferredWipeout: true, deleteDirs: true) + checkout scm + sh '''#!/bin/bash + make clean vendor lint build dist doc + ''' + } + } + // stage('Build Windows') { + // agent{ label 'windows' } + // environment { + // GO_OPT = ' ' + // CGO_ENABLED = 0 + // } + // steps { + // echo "***** BUILD ${PROJECT_NAME} on Windows *****" + // cleanWs(disableDeferredWipeout: true, deleteDirs: true) + // catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') { + // checkout scm + // bat 'make clean vendor build dist pkg-msi' + // } + // } + // post { + // always { + // script { + // if (getContext(hudson.FilePath)) { + // archiveArtifacts ( + // artifacts: 'out/*.zip,out/*.msi', + // allowEmptyArchive: true, + // fingerprint: true, + // onlyIfSuccessful: true, + // ) + // } + // } + // } + // } + // } + } + } + stage('Test') { + environment { + EXPORT_RESULT = true + COVERAGE_FORMAT = 'xml' + } + steps { + echo "===== TEST ${PROJECT_NAME} =====" + sh '''#!/bin/bash + make test coverage + ''' + } + } + stage('Doc') { + when { anyOf { + branch 'main' + branch 'develop' + branch 'release/*' + branch 'support/*' + tag 'v*' + } } + environment { + DOC_FORMAT = 'pdf' + } + steps { + echo "===== MAKE ${PROJECT_NAME} Documentation =====" + sh '''#!/bin/bash + make doc + ''' + } + } + stage('Draft Release') { + when { tag 'v*' } + steps { + script { + def version = "${TAG_NAME}".substring(1) + RELEASE_ID = msCreateRelease( + "${PROJECT_OWNER}", + "${PROJECT_ID}", + "${TAG_NAME}", + "${PROJECT_NAME}", + ) + } + } + } + stage('Release') { + parallel { + stage('Release Linux') { + when { tag 'v*' } + environment { + OUTDIR = 'dist' + DIST_TAG = 'empty' + GO_OPT = ' ' + } + steps { + echo "***** RELEASE ${PROJECT_NAME} for Linux *****" + sh '''#!/bin/bash + make build dist + ''' + script { + msUploadFilesToRelease( + "${PROJECT_OWNER}", + "${PROJECT_ID}", + RELEASE_ID, + ['dist/*.tar.gz', 'out/doc/*.pdf'], + ) + if( currentBuild.currentResult == 'SUCCESS' ) { + currentBuild.keepLog = true + } + } + msSendRocketChat("${ROCKET_TITLE}", "Released assets for Linux", 'blue') + } + } + stage('Release Windows') { + agent{ label 'windows' } + when { tag 'v*' } + environment { + OUTDIR = 'dist' + DIST_TAG = 'empty' + GO_OPT = ' ' + } + steps { + echo "***** RELEASE ${PROJECT_NAME} for Windows *****" + bat 'make build dist pkg-msi' + script { + msUploadFilesToRelease( + "${PROJECT_OWNER}", + "${PROJECT_ID}", + RELEASE_ID, + ['dist/*.msi'], + ) + if( currentBuild.currentResult == 'SUCCESS' ) { + currentBuild.keepLog = true + } + } + msSendRocketChat("${ROCKET_TITLE}", "Released assets for Windows", 'blue') + } + } + } + } + } + + post { + always { + script { + if (getContext(hudson.FilePath)) { + junit ( + testResults: 'out/junit-report.xml', + allowEmptyResults: false, + skipPublishingChecks: true, + ) + cobertura ( + coberturaReportFile: 'out/coverage.xml', + failNoReports: true, + ) + archiveArtifacts ( + artifacts: 'out/*.tar.*,out/*.zip,out/*.msi', + allowEmptyArchive: false, + fingerprint: true, + onlyIfSuccessful: true, + ) + archiveArtifacts ( + artifacts: 'out/doc/*.pdf', + allowEmptyArchive: true, + fingerprint: true, + onlyIfSuccessful: true, + ) + if (currentBuild.result == 'SUCCESS') { + publishHTML(target: [ + allowMissing: true, + alwaysLinkToLastBuild: true, + keepAll: false, + reportDir: 'out/doc/html', + reportFiles: 'godoc/index.html', + reportTitles: 'Техническая документация', + reportName: 'Documentation', + ]) + } + } + if( currentBuild.result != 'SUCCESS' ) { + currentBuild.keepLog = false + } + def timeSec = currentBuild.duration / 1000 + msSendRocketChat( + "${ROCKET_TITLE}", + "Build ${currentBuild.result} after ${timeSec} sec", + msBuildResultColor(), + ) + } + } + } +} diff --git a/cmd/drawio-export/main.go b/cmd/drawio-export/main.go new file mode 100644 index 0000000..99fc8a2 --- /dev/null +++ b/cmd/drawio-export/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Draw.io Exporter") +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..ae6c96b --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.mousesoft.ru/ms/drawio-exporter + +go 1.20 diff --git a/makefile b/makefile new file mode 100644 index 0000000..51e2d38 --- /dev/null +++ b/makefile @@ -0,0 +1,136 @@ +# drawio-exporter makefile +# ======================== + +PROJECT_NAME := drawio-exporter + +TMPDIR ?= $(CURDIR)/tmp +OUTDIR ?= $(CURDIR)/out +BINDIR ?= $(OUTDIR)/bin + +VERSION ?= $(strip $(shell ./scripts/version.sh)) +VERSION_NUMBER := $(strip $(shell ./scripts/version.sh number)) +DIST_KIND := $(shell uname -m) + +GO_OPT_BASE := -mod vendor -ldflags "-X main.version=${VERSION}" +GO_OPT ?= +EXPORT_RESULT ?= false # for CI please set EXPORT_RESULT to true +COVERAGE_FORMAT ?= html + +GOCMD := go +GOTEST := $(GOCMD) test +GOVET := $(GOCMD) vet +ECHO_CMD := echo + +ifeq ($(OS),Windows_NT) +DIST_SUFFIX := windows-$(DIST_KIND) +MSI_FILE := $(PROJECT_NAME)_$(VERSION)_$(DIST_KIND).msi +DIST_EXT := .zip +DIST_OPTS := -a -cf +ECHO_CMD := echo -e +else +PLATFORM := $(shell uname -s | tr '[:upper:]' '[:lower:]') +DIST_SUFFIX := $(PLATFORM)-$(DIST_KIND) +DIST_EXT := .tar.gz +DIST_OPTS := -czf +endif + +PKG_NAME := $(PROJECT_NAME)_$(VERSION)_$(DIST_SUFFIX) +DIST_FILE := $(PKG_NAME)$(DIST_EXT) + +GREEN := $(shell tput -Txterm setaf 2) +YELLOW := $(shell tput -Txterm setaf 3) +WHITE := $(shell tput -Txterm setaf 7) +CYAN := $(shell tput -Txterm setaf 6) +RESET := $(shell tput -Txterm sgr0) + +.PHONY: all version version-number test build dist vendor + +version: ## Version of the project to be built + @echo $(VERSION) + +version-number: ## Version number of the project to be built + @echo $(VERSION_NUMBER) + +## Build: + +all: clean vendor build ## Build binary + +APPS = $(patsubst cmd/%/, %, $(dir $(wildcard cmd/*/main.go))) + +build: $(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}" + +$(BINDIR)/%: cmd/%/main.go $(patsubst cmd/%/main.go,cmd/%/*.go,$<) + GO111MODULE=on $(GOCMD) build $(GO_OPT_BASE) $(GO_OPT) \ + -o $(BINDIR)/$(BIN_PREFIX)$(patsubst cmd/%/main.go,%,$<)$(BIN_SUFFIX) \ + $(patsubst %/main.go,./%,$<) + +dist: ## 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}" + +vendor: ## Copy of all packages needed to support builds and tests in the vendor directory. + $(GOCMD) mod vendor + @echo "Vendor\t\t${GREEN}[OK]${RESET}" + +clean: ## Remove build related files + @rm -fr $(TMPDIR) + @rm -fr $(OUTDIR) + @rm -fr dist/ + @$(ECHO_CMD) "Clean\t\t${GREEN}[OK]${RESET}" + +## Test: +test: ## Run the tests of the project +ifeq ($(EXPORT_RESULT), true) + @mkdir -p $(OUTDIR) + $(eval OUTPUT_OPTIONS = | go-junit-report -set-exit-code > $(OUTDIR)/junit-report.xml) +endif + $(GOTEST) -v $(GO_OPT) ./... $(OUTPUT_OPTIONS) + @echo "Test\t\t${GREEN}[OK]${RESET}" + +coverage: ## Run the tests of the project and export the coverage report. + @mkdir -p out + $(GOTEST) -cover -covermode=count -coverprofile=$(OUTDIR)/profile.cov ./... + $(GOCMD) tool cover -func $(OUTDIR)/profile.cov +ifeq ($(EXPORT_RESULT), true) +ifeq ($(COVERAGE_FORMAT), html) + gocov convert $(OUTDIR)/profile.cov | gocov-html > $(OUTDIR)/coverage.html +else + gocov convert $(OUTDIR)/profile.cov | gocov-xml > $(OUTDIR)/coverage.xml +endif +endif + @echo "Coverage\t${GREEN}[OK]${RESET}" + +## Lint: +lint: lint-go ## Run all available linters. + @echo "Lint\t\t${GREEN}[OK]${RESET}" + +lint-go: + go fmt ./... + go vet ./... + +## Documentation: +doc: doc-golds ## Generate all documents. + @echo "Doc\t\t${GREEN}[OK]${RESET}" + +doc-common: + @mkdir -p $(DOC_DIR) + +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 ./pkg/hexgrid + +## Help: +help: ## Show this help. + @echo '' + @echo 'Usage:' + @echo ' ${YELLOW}make${RESET} ${GREEN}${RESET}' + @echo '' + @echo 'Targets:' + @awk 'BEGIN {FS = ":.*?## "} { \ + 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) diff --git a/scripts/changes.awk b/scripts/changes.awk new file mode 100644 index 0000000..8441a80 --- /dev/null +++ b/scripts/changes.awk @@ -0,0 +1,20 @@ +# Get changes of given version number. +{ + while (index($0, "## [" + version + "]") <= 0) { + if (getline <= 0) { + exit + } + } + if (getline <= 0 ) { + exit + } + if (getline <= 0 ) { + exit + } + while (index($0, "## [") <= 0) { + print $0 + if (getline <= 0) { + exit + } + } +} \ No newline at end of file diff --git a/scripts/version.sh b/scripts/version.sh new file mode 100755 index 0000000..d0426f4 --- /dev/null +++ b/scripts/version.sh @@ -0,0 +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) +else +GIT_VERSION=${TAG_NAME} +fi + +if [ -z ${VERSION+x} ]; then +VERSION=$(echo ${GIT_VERSION} | sed -e 's|^origin/||') +fi + +if [ -z $1 ]; then +echo "${VERSION}" +else +echo ${VERSION} | sed -e 's/^v//' +fi