Skip to content

Commit

Permalink
cache binaries in CI, set release title
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewChubatiuk committed Dec 20, 2024
1 parent 956a0ba commit ffa4375
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 24 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/pr-checks-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,26 @@ jobs:
steps:
- name: Code checkout
uses: actions/checkout@v4

- name: Restore binaries from cache
uses: actions/cache/restore@v4
with:
path: ./bin
key: binary
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
check-latest: true
cache: true

- name: Dependencies
run: |
make check-all
git diff --exit-code
- name: Prapare binary cache
uses: actions/cache@v4
with:
path: ./bin
key: binary
test:
needs: lint
strategy:
Expand All @@ -58,14 +65,12 @@ jobs:
steps:
- name: Code checkout
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
check-latest: true
cache: true

- name: run tests
run: |
make ${{ matrix.scenario }}
15 changes: 14 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Restore binaries from cache
uses: actions/cache/restore@v4
with:
path: ./bin
key: binary
- name: Setup Go
uses: actions/setup-go@v5
with:
Expand Down Expand Up @@ -61,12 +66,20 @@ jobs:
git tag ${TAG}
git push origin ${TAG}
fi
- name: Prapare binary cache
if: ${{ hashFiles('NOTES.md') != '' }}
uses: actions/cache@v4
with:
path: ./bin
key: binary
- name: Upload release assets
if: ${{ hashFiles('NOTES.md') != '' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create ${{ env.PKG_TAG }} --notes-file=NOTES.md ./dist/*
gh release create ${{ env.PKG_TAG }} \
--title=${{ env.PKG_TAG }} \
--notes-file=NOTES.md ./dist/*
- name: Automatic changelog update
if: ${{ hashFiles('NOTES.md') != '' }}
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ lib-cov
coverage

# Compiled binary addons (https://nodejs.org/api/addons.html)
bin/
dist/
victorialogs-datasource/
plugins/
Expand Down
9 changes: 3 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
run:
timeout: 2m
skip-dirs:
- go
- opt

linters:
enable:
- revive

issues:
exclude-dirs:
- go
- opt
exclude-rules:
- linters:
- staticcheck
text: "SA(4003|1019|5011):"

include:
- EXC0012
- EXC0014
59 changes: 47 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ app-via-docker-local:
$(eval ARCH := $(shell docker run $(GO_BUILDER_IMAGE) go env GOARCH))
$(MAKE) app-via-docker-$(OS)-$(ARCH)

vl-backend-plugin-build:
which mage || go install github.com/magefile/[email protected] && mage -v
vl-backend-plugin-build: mage
$(MAGE) -v

vl-frontend-plugin-build: frontend-build

Expand Down Expand Up @@ -73,11 +73,8 @@ golang-test:
golang-test-race:
go test -race ./pkg/...

golang-ci-lint: install-golang-ci-lint
golangci-lint run ./pkg/...

install-golang-ci-lint:
which golangci-lint || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.62.2
lint: golangci-lint
$(GOLANGCI_LINT) run ./pkg/...

fmt:
gofmt -l -w -s ./pkg
Expand All @@ -87,9 +84,47 @@ vet:

check-all: fmt vet golang-ci-lint

vl-plugin-check-install:
which plugincheck2 || go install github.com/grafana/plugin-validator/pkg/cmd/[email protected]

vl-plugin-check: vl-plugin-release vl-plugin-check-install
vl-plugin-check: vl-plugin-release plugincheck2
$(eval PACKAGE_NAME := $(PLUGIN_ID)-$(PKG_TAG)) \
plugincheck2 -sourceCodeUri file://$(shell pwd)/ "$(shell pwd)/dist/${PACKAGE_NAME}.zip"
$(PLUGINCHECK2) -sourceCodeUri file://$(shell pwd)/ "$(shell pwd)/dist/${PACKAGE_NAME}.zip"

LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

PLUGINCHECK2 = $(LOCALBIN)/plugincheck2-$(PLUGINCHECK2_VERSION)
MAGE = $(LOCALBIN)/mage-$(MAGE_VERSION)
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)

PLUGINCHECK2_VERSION = v0.20.3
MAGE_VERSION = v1.15.0
GOLANGCI_LINT_VERSION = v1.62.2

.PHONY: plugincheck2
plugincheck2: $(PLUGINCHECK2)
$(PLUGINCHECK2): $(LOCALBIN)
$(call go-install-tool,$(PLUGINCHECK2),github.com/grafana/plugin-validator/pkg/cmd/plugincheck2,$(PLUGINCHECK2_VERSION))

.PHONY: mage
mage: $(MAGE)
$(MAGE): $(LOCALBIN)
$(call go-install-tool,$(MAGE),github.com/magefile/mage,$(MAGE_VERSION))

.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))

# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary (ideally with version)
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f $(1) ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) || echo "move not needed" ;\
}
endef

0 comments on commit ffa4375

Please sign in to comment.