From 965b4e67185df570d3b7529497d5ca8da5a66fd9 Mon Sep 17 00:00:00 2001 From: Vladimir Avtsenov Date: Sat, 15 Feb 2025 00:03:02 +0300 Subject: [PATCH 1/8] fix tests --- models/rule_test.go | 8 ++++---- records/records_test.go | 29 +++++++++++++++-------------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/models/rule_test.go b/models/rule_test.go index e83c9f2..589fcb7 100644 --- a/models/rule_test.go +++ b/models/rule_test.go @@ -2,16 +2,16 @@ package models import "testing" -func TestDomain_IsMatch_Plaintext(t *testing.T) { +func TestDomain_IsMatch_Domain(t *testing.T) { rule := &Rule{ - Type: "plaintext", + Type: "domain", Rule: "example.com", } if !rule.IsMatch("example.com") { - t.Fatal("&Rule{Type: \"plaintext\", Rule: \"example.com\"}.IsMatch(\"example.com\") returns false") + t.Fatal("&Rule{Type: \"domain\", Rule: \"example.com\"}.IsMatch(\"example.com\") returns false") } if rule.IsMatch("noexample.com") { - t.Fatal("&Rule{Type: \"plaintext\", Rule: \"example.com\"}.IsMatch(\"noexample.com\") returns true") + t.Fatal("&Rule{Type: \"domain\", Rule: \"example.com\"}.IsMatch(\"noexample.com\") returns true") } } diff --git a/records/records_test.go b/records/records_test.go index 90d782e..cbe18ab 100644 --- a/records/records_test.go +++ b/records/records_test.go @@ -9,8 +9,8 @@ import ( func TestLoop(t *testing.T) { r := New() - r.AddCNameRecord("1", "2", time.Minute) - r.AddCNameRecord("2", "1", time.Minute) + r.AddCNameRecord("1", "2", 60) + r.AddCNameRecord("2", "1", 60) if r.GetARecords("1") != nil { t.Fatal("loop detected") } @@ -21,8 +21,8 @@ func TestLoop(t *testing.T) { func TestCName(t *testing.T) { r := New() - r.AddARecord("example.com", []byte{1, 2, 3, 4}, time.Minute) - r.AddCNameRecord("gateway.example.com", "example.com", time.Minute) + r.AddARecord("example.com", []byte{1, 2, 3, 4}, 60) + r.AddCNameRecord("gateway.example.com", "example.com", 60) records := r.GetARecords("gateway.example.com") if records == nil { t.Fatal("no records") @@ -34,7 +34,7 @@ func TestCName(t *testing.T) { func TestA(t *testing.T) { r := New() - r.AddARecord("example.com", []byte{1, 2, 3, 4}, time.Minute) + r.AddARecord("example.com", []byte{1, 2, 3, 4}, 60) records := r.GetARecords("example.com") if records == nil { t.Fatal("no records") @@ -46,7 +46,8 @@ func TestA(t *testing.T) { func TestDeprecated(t *testing.T) { r := New() - r.AddARecord("example.com", []byte{1, 2, 3, 4}, -time.Minute) + r.AddARecord("example.com", []byte{1, 2, 3, 4}, 0) + time.Sleep(time.Second) records := r.GetARecords("example.com") if records != nil { t.Fatal("deprecated records") @@ -63,7 +64,7 @@ func TestNotExistedA(t *testing.T) { func TestNotExistedCNameAlias(t *testing.T) { r := New() - r.AddCNameRecord("gateway.example.com", "example.com", time.Minute) + r.AddCNameRecord("gateway.example.com", "example.com", 60) records := r.GetARecords("gateway.example.com") if records != nil { t.Fatal("not existed records") @@ -72,8 +73,8 @@ func TestNotExistedCNameAlias(t *testing.T) { func TestReplacing(t *testing.T) { r := New() - r.AddCNameRecord("gateway.example.com", "example.com", time.Minute) - r.AddARecord("gateway.example.com", []byte{1, 2, 3, 4}, time.Minute) + r.AddCNameRecord("gateway.example.com", "example.com", 60) + r.AddARecord("gateway.example.com", []byte{1, 2, 3, 4}, 60) records := r.GetARecords("gateway.example.com") if bytes.Compare(records[0].Address, []byte{1, 2, 3, 4}) != 0 { t.Fatal("mismatch") @@ -82,11 +83,11 @@ func TestReplacing(t *testing.T) { func TestAliases(t *testing.T) { r := New() - r.AddARecord("1", []byte{1, 2, 3, 4}, time.Minute) - r.AddCNameRecord("2", "1", time.Minute) - r.AddCNameRecord("3", "2", time.Minute) - r.AddCNameRecord("4", "2", time.Minute) - r.AddCNameRecord("5", "1", time.Minute) + r.AddARecord("1", []byte{1, 2, 3, 4}, 60) + r.AddCNameRecord("2", "1", 60) + r.AddCNameRecord("3", "2", 60) + r.AddCNameRecord("4", "2", 60) + r.AddCNameRecord("5", "1", 60) aliases := r.GetAliases("1") if aliases == nil { t.Fatal("no aliases") From 7833bc3db49ca47da64d2c1e24903caf56c2e05f Mon Sep 17 00:00:00 2001 From: Vladimir Avtsenov Date: Sat, 15 Feb 2025 00:40:06 +0300 Subject: [PATCH 2/8] build nightly versions --- .github/workflows/build.yml | 2 -- Makefile | 14 +++++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c7630a2..43f294c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,8 +2,6 @@ name: Build and Package OPKG on: push: - branches: - - main jobs: build: diff --git a/Makefile b/Makefile index 0718d7c..824cd2c 100644 --- a/Makefile +++ b/Makefile @@ -2,10 +2,14 @@ APP_NAME = magitrickle APP_DESCRIPTION = DNS-based routing application APP_MAINTAINER = Vladimir Avtsenov -TAG = $(shell git describe --tags --abbrev=0 2> /dev/null || git rev-parse --short HEAD) COMMIT = $(shell git rev-parse --short HEAD) -COMMITS_SINCE_TAG = $(shell git rev-list ${TAG}..HEAD --count || echo "0") -VERSION ?= $(TAG) +UPSTREAM_VERSION ?= $(shell git describe --tags --abbrev=0 2> /dev/null || echo $(COMMIT)) +OPKG_REVISION = ~git$(shell date +%Y%m%d).$(COMMIT)-1 +ifeq ($(shell git rev-parse --abbrev-ref HEAD), main) + TAG = $(shell git describe --tags --abbrev=0 2> /dev/null || echo $(COMMIT)) + COMMITS_SINCE_TAG = $(shell git rev-list ${TAG}..HEAD --count || echo "0") + OPKG_REVISION = -$(shell expr $(COMMITS_SINCE_TAG) + 1) +endif ARCH ?= mipsel GOOS ?= linux @@ -16,7 +20,7 @@ GOARM ?= BUILD_DIR = ./.build PKG_DIR = $(BUILD_DIR)/$(ARCH) BIN_DIR = $(PKG_DIR)/data/opt/bin -PARAMS = -v -a -trimpath -ldflags="-X 'magitrickle/constant.Version=$(VERSION)' -X 'magitrickle/constant.Commit=$(COMMIT)' -w -s" +PARAMS = -v -a -trimpath -ldflags="-X 'magitrickle/constant.Version=$(UPSTREAM_VERSION)$(OPKG_REVISION)' -X 'magitrickle/constant.Commit=$(COMMIT)' -w -s" all: clear build_daemon package @@ -30,7 +34,7 @@ package: @mkdir -p $(PKG_DIR)/control @echo '2.0' > $(PKG_DIR)/debian-binary @echo 'Package: $(APP_NAME)' > $(PKG_DIR)/control/control - @echo 'Version: $(VERSION)-$(COMMITS_SINCE_TAG)' >> $(PKG_DIR)/control/control + @echo 'Version: $(UPSTREAM_VERSION)$(OPKG_REVISION)' >> $(PKG_DIR)/control/control @echo 'Architecture: $(ARCH)' >> $(PKG_DIR)/control/control @echo 'Maintainer: $(APP_MAINTAINER)' >> $(PKG_DIR)/control/control @echo 'Description: $(APP_DESCRIPTION)' >> $(PKG_DIR)/control/control From 9926cfa0fb28592b165af7b97a01e8ccb5537908 Mon Sep 17 00:00:00 2001 From: Vladimir Avtsenov Date: Sat, 15 Feb 2025 00:47:22 +0300 Subject: [PATCH 3/8] downgrading actions/setup-go --- .github/workflows/build.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 43f294c..3661206 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,10 +41,9 @@ jobs: fetch-tags: true - name: Set up Go - uses: actions/setup-go@v5 + uses: actions/setup-go@v3 with: go-version: '1.21' - cache: false - name: Install dependencies run: | From 1ab11fa89911329a59118cf4cf015699d8244f0f Mon Sep 17 00:00:00 2001 From: Vladimir Avtsenov Date: Sat, 15 Feb 2025 00:58:29 +0300 Subject: [PATCH 4/8] test release --- .github/workflows/build.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3661206..4dd8b91 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,6 +2,8 @@ name: Build and Package OPKG on: push: + release: + types: [published] jobs: build: @@ -61,3 +63,13 @@ jobs: path: .build/magitrickle_${{ matrix.arch }}.ipk if-no-files-found: error compression-level: 0 + + - name: Upload asset to release + if: ${{ github.event_name == 'release' }} + uses: https://gitea.com/actions/release-action@main + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + files: |- + .build/*.ipk + api_key: '${{secrets.RELEASE_TOKEN}}' From 867788dc4c65e2a634e02eddb43ce17ace0fb261 Mon Sep 17 00:00:00 2001 From: Vladimir Avtsenov Date: Sat, 15 Feb 2025 01:05:46 +0300 Subject: [PATCH 5/8] ignore tags --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4dd8b91..9af1b13 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,6 +2,8 @@ name: Build and Package OPKG on: push: + branches-ignore: + - 'refs/tags/*' release: types: [published] From cc8d3ede3c1c4f6bf8e9fe9b22cf0a69decef6e3 Mon Sep 17 00:00:00 2001 From: Vladimir Avtsenov Date: Sat, 15 Feb 2025 01:10:28 +0300 Subject: [PATCH 6/8] place version in filename --- .github/workflows/build.yml | 6 +++--- Makefile | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9af1b13..754deae 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -61,8 +61,8 @@ jobs: - name: Upload artifact uses: actions/upload-artifact@v3 with: - name: magitrickle_${{ matrix.arch }}.ipk.zip - path: .build/magitrickle_${{ matrix.arch }}.ipk + name: magitrickle_${{ matrix.arch }} + path: .build/magitrickle_*_${{ matrix.arch }}.ipk if-no-files-found: error compression-level: 0 @@ -73,5 +73,5 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: files: |- - .build/*.ipk + .build/magitrickle_*_${{ matrix.arch }}.ipk api_key: '${{secrets.RELEASE_TOKEN}}' diff --git a/Makefile b/Makefile index 824cd2c..3935f58 100644 --- a/Makefile +++ b/Makefile @@ -44,4 +44,4 @@ package: @cp -r ./opt $(PKG_DIR)/data/ @fakeroot sh -c "tar -C $(PKG_DIR)/control -czvf $(PKG_DIR)/control.tar.gz ." @fakeroot sh -c "tar -C $(PKG_DIR)/data -czvf $(PKG_DIR)/data.tar.gz ." - @tar -C $(PKG_DIR) -czvf $(BUILD_DIR)/$(APP_NAME)_$(ARCH).ipk ./debian-binary ./control.tar.gz ./data.tar.gz + @tar -C $(PKG_DIR) -czvf $(BUILD_DIR)/$(APP_NAME)_$(UPSTREAM_VERSION)$(OPKG_REVISION)_$(ARCH).ipk ./debian-binary ./control.tar.gz ./data.tar.gz From c7dac46d67f857415e999bf4318fea5aa01aa791 Mon Sep 17 00:00:00 2001 From: Vladimir Avtsenov Date: Sat, 15 Feb 2025 01:18:24 +0300 Subject: [PATCH 7/8] fix arch name --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3935f58..e0a0794 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ ifeq ($(shell git rev-parse --abbrev-ref HEAD), main) OPKG_REVISION = -$(shell expr $(COMMITS_SINCE_TAG) + 1) endif -ARCH ?= mipsel +ARCH ?= mipsel-3.4 GOOS ?= linux GOARCH ?= mipsle GOMIPS ?= softfloat From e8d53872b0eefda5d7491fa2b4e81b534578ad0e Mon Sep 17 00:00:00 2001 From: Vladimir Avtsenov Date: Sat, 15 Feb 2025 01:18:45 +0300 Subject: [PATCH 8/8] upload only for releases --- .../workflows/{build.yml => build-for-release.yml} | 12 ------------ 1 file changed, 12 deletions(-) rename .github/workflows/{build.yml => build-for-release.yml} (82%) diff --git a/.github/workflows/build.yml b/.github/workflows/build-for-release.yml similarity index 82% rename from .github/workflows/build.yml rename to .github/workflows/build-for-release.yml index 754deae..cac57fd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build-for-release.yml @@ -1,9 +1,6 @@ name: Build and Package OPKG on: - push: - branches-ignore: - - 'refs/tags/*' release: types: [published] @@ -58,16 +55,7 @@ jobs: run: | ARCH=${{ matrix.arch }} GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} GOMIPS=${{ matrix.gomips }} GOARM=${{ matrix.goarm }} make - - name: Upload artifact - uses: actions/upload-artifact@v3 - with: - name: magitrickle_${{ matrix.arch }} - path: .build/magitrickle_*_${{ matrix.arch }}.ipk - if-no-files-found: error - compression-level: 0 - - name: Upload asset to release - if: ${{ github.event_name == 'release' }} uses: https://gitea.com/actions/release-action@main env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}