From d362f2cdd3dc58b69eca433055fbef3976d2c7cd Mon Sep 17 00:00:00 2001 From: Li Jie Date: Sat, 9 Mar 2024 11:32:50 +0800 Subject: [PATCH 1/6] check files of snapcrafts and nfpms in goreleaser configuration --- .github/workflows/check_goreleaser_config.py | 42 +++++ .github/workflows/go.yml | 3 + .github/workflows/release-build.yml | 3 + .gitignore | 2 +- .goreleaser.yaml | 175 ++++++++++++------- 5 files changed, 162 insertions(+), 63 deletions(-) create mode 100644 .github/workflows/check_goreleaser_config.py diff --git a/.github/workflows/check_goreleaser_config.py b/.github/workflows/check_goreleaser_config.py new file mode 100644 index 000000000..b99d9db84 --- /dev/null +++ b/.github/workflows/check_goreleaser_config.py @@ -0,0 +1,42 @@ +import os +import subprocess +import yaml + +files = [f for f in os.listdir('.') if not f.startswith(".")] +files.sort() +# filter out the files that are ignored by git +files = [f for f in files if subprocess.call( + ["git", "ls-files", "--error-unmatch", f], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL) == 0] + +gorel = yaml.load(open(".goreleaser.yaml", "r"), Loader=yaml.FullLoader) +scfiles = [f["source"] for f in gorel["snapcrafts"][0]["extra_files"]] +scfiles.sort() + +failed = False + +if files != scfiles: + failed = True + print("Files in snapcraft are different from the ones in the repo") + print("Update .goreleaser.yaml in the snapcraft section:") + for f in files: + print(f" - source: \"{f}\"") + print(f" destination: \"{f}\"") + +nfpms_files = [f["src"] + for f in gorel["nfpms"][0]["contents"] if f.get("type") != "symlink"] +nfpms_files.sort() + +if files != nfpms_files: + failed = True + print("Files in nfpms are different from the ones in the repo") + print("Update .goreleaser.yaml in the nfpms section:") + for f in files: + print(f" - src: \"{f}\"") + print(f" dst: \"/usr/lib/{{ .ProjectName }}/{f}\"") + +if failed: + exit(1) + +print(".goreleaser checks passed") diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 18c6fb3a6..279117af8 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -15,6 +15,9 @@ jobs: runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 + + - name: Check goreleaser files + run: python .github/workflows/check_goreleaser_config.py - name: Set up Go uses: actions/setup-go@v5 diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml index 6e6e4154d..c9008b594 100644 --- a/.github/workflows/release-build.yml +++ b/.github/workflows/release-build.yml @@ -12,6 +12,9 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 + + - name: Check goreleaser configuration + run: python .github/workflows/check_goreleaser_config.py - name: Install Snapcraft uses: samuelmeuli/action-snapcraft@v2 diff --git a/.gitignore b/.gitignore index 4619940eb..29fa5fdb7 100644 --- a/.gitignore +++ b/.gitignore @@ -50,4 +50,4 @@ bin/ go-num/ _todo*.go -dist/ +.dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml index cffa2061e..3febbf374 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -4,6 +4,7 @@ # vim: set ts=2 sw=2 tw=0 fo=cnqoj version: 1 +dist: ".dist" before: hooks: @@ -146,42 +147,66 @@ nfpms: bindir: /usr/lib/{{ .ProjectName }} contents: # source folder - - src: LICENSE - dst: /usr/lib/{{ .ProjectName }}/LICENSE + - src: "LICENSE" + dst: "/usr/lib/{ .ProjectName }/LICENSE" + - src: "Makefile" + dst: "/usr/lib/{ .ProjectName }/Makefile" - src: "README.md" - dst: /usr/lib/{{ .ProjectName }}/README.md + dst: "/usr/lib/{ .ProjectName }/README.md" + - src: "_gendeps.go" + dst: "/usr/lib/{ .ProjectName }/_gendeps.go" + - src: "all.bash" + dst: "/usr/lib/{ .ProjectName }/all.bash" + - src: "all.bat" + dst: "/usr/lib/{ .ProjectName }/all.bat" + - src: "ast" + dst: "/usr/lib/{ .ProjectName }/ast" + - src: "build_install_run.go" + dst: "/usr/lib/{ .ProjectName }/build_install_run.go" + - src: "builtin" + dst: "/usr/lib/{ .ProjectName }/builtin" + - src: "cl" + dst: "/usr/lib/{ .ProjectName }/cl" + - src: "cmd" + dst: "/usr/lib/{ .ProjectName }/cmd" + - src: "doc" + dst: "/usr/lib/{ .ProjectName }/doc" + - src: "env" + dst: "/usr/lib/{ .ProjectName }/env" + - src: "format" + dst: "/usr/lib/{ .ProjectName }/format" + - src: "gengo.go" + dst: "/usr/lib/{ .ProjectName }/gengo.go" - src: "go.mod" - dst: /usr/lib/{{ .ProjectName }}/go.mod + dst: "/usr/lib/{ .ProjectName }/go.mod" - src: "go.sum" - dst: /usr/lib/{{ .ProjectName }}/go.sum - - src: "*.go" - dst: /usr/lib/{{ .ProjectName }}/ - - src: ast - dst: /usr/lib/{{ .ProjectName }}/ast - - src: builtin - dst: /usr/lib/{{ .ProjectName }}/builtin - - src: cl - dst: /usr/lib/{{ .ProjectName }}/cl - - src: cmd - dst: /usr/lib/{{ .ProjectName }}/cmd - - src: doc - dst: /usr/lib/{{ .ProjectName }}/doc - - src: env - dst: /usr/lib/{{ .ProjectName }}/env - - src: format - dst: /usr/lib/{{ .ProjectName }}/format - - src: parser - dst: /usr/lib/{{ .ProjectName }}/parser - - src: printer - dst: /usr/lib/{{ .ProjectName }}/parser - - src: scanner - dst: /usr/lib/{{ .ProjectName }}/scanner - - src: token - dst: /usr/lib/{{ .ProjectName }}/token - - src: watcher - dst: /usr/lib/{{ .ProjectName }}/watcher + dst: "/usr/lib/{ .ProjectName }/go.sum" + - src: "imp.go" + dst: "/usr/lib/{ .ProjectName }/imp.go" + - src: "load.go" + dst: "/usr/lib/{ .ProjectName }/load.go" + - src: "make.bash" + dst: "/usr/lib/{ .ProjectName }/make.bash" + - src: "make.bat" + dst: "/usr/lib/{ .ProjectName }/make.bat" + - src: "outline.go" + dst: "/usr/lib/{ .ProjectName }/outline.go" + - src: "parser" + dst: "/usr/lib/{ .ProjectName }/parser" + - src: "printer" + dst: "/usr/lib/{ .ProjectName }/printer" + - src: "scanner" + dst: "/usr/lib/{ .ProjectName }/scanner" + - src: "test" + dst: "/usr/lib/{ .ProjectName }/test" + - src: "testdata" + dst: "/usr/lib/{ .ProjectName }/testdata" + - src: "tidy.go" + dst: "/usr/lib/{ .ProjectName }/tidy.go" + - src: "token" + dst: "/usr/lib/{ .ProjectName }/token" - src: "x" - dst: /usr/lib/{{ .ProjectName }}/x + dst: "/usr/lib/{ .ProjectName }/x" # symlinks to binaries - src: "/usr/lib/{{ .ProjectName }}/bin/gop" dst: /usr/bin/gop @@ -211,40 +236,66 @@ snapcrafts: {{- if .Arm }}v{{ .Arm }}{{ end }} extra_files: # source folder - - source: LICENSE - destination: LICENSE + - source: "LICENSE" + destination: "LICENSE" + - source: "Makefile" + destination: "Makefile" - source: "README.md" - destination: README.md + destination: "README.md" + - source: "_gendeps.go" + destination: "_gendeps.go" + - source: "all.bash" + destination: "all.bash" + - source: "all.bat" + destination: "all.bat" + - source: "ast" + destination: "ast" + - source: "build_install_run.go" + destination: "build_install_run.go" + - source: "builtin" + destination: "builtin" + - source: "cl" + destination: "cl" + - source: "cmd" + destination: "cmd" + - source: "doc" + destination: "doc" + - source: "env" + destination: "env" + - source: "format" + destination: "format" + - source: "gengo.go" + destination: "gengo.go" - source: "go.mod" - destination: go.mod + destination: "go.mod" - source: "go.sum" - destination: go.sum - - source: ast - destination: ast - - source: builtin - destination: builtin - - source: cl - destination: cl - - source: cmd - destination: cmd - - source: doc - destination: doc - - source: env - destination: env - - source: format - destination: format - - source: parser - destination: parser - - source: printer - destination: parser - - source: scanner - destination: scanner - - source: token - destination: token - - source: watcher - destination: watcher + destination: "go.sum" + - source: "imp.go" + destination: "imp.go" + - source: "load.go" + destination: "load.go" + - source: "make.bash" + destination: "make.bash" + - source: "make.bat" + destination: "make.bat" + - source: "outline.go" + destination: "outline.go" + - source: "parser" + destination: "parser" + - source: "printer" + destination: "printer" + - source: "scanner" + destination: "scanner" + - source: "test" + destination: "test" + - source: "testdata" + destination: "testdata" + - source: "tidy.go" + destination: "tidy.go" + - source: "token" + destination: "token" - source: "x" - destination: x + destination: "x" apps: gop: command: "gop" From 4aa2e5bfbd55924ea0edbebff36e15e86e5a7593 Mon Sep 17 00:00:00 2001 From: Li Jie Date: Sat, 9 Mar 2024 12:12:28 +0800 Subject: [PATCH 2/6] ci: install pyyaml for check script --- .github/workflows/go.yml | 4 +++- .github/workflows/release-build.yml | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 279117af8..547650638 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -17,7 +17,9 @@ jobs: - uses: actions/checkout@v4 - name: Check goreleaser files - run: python .github/workflows/check_goreleaser_config.py + run: | + pip install --no-input pyyaml + python .github/workflows/check_goreleaser_config.py - name: Set up Go uses: actions/setup-go@v5 diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml index c9008b594..d24eef531 100644 --- a/.github/workflows/release-build.yml +++ b/.github/workflows/release-build.yml @@ -13,8 +13,10 @@ jobs: with: fetch-depth: 0 - - name: Check goreleaser configuration - run: python .github/workflows/check_goreleaser_config.py + - name: Check goreleaser files + run: | + pip install --no-input pyyaml + python .github/workflows/check_goreleaser_config.py - name: Install Snapcraft uses: samuelmeuli/action-snapcraft@v2 From 81fc84f7317e00cd327cb7d0373d39adb358be7b Mon Sep 17 00:00:00 2001 From: Li Jie Date: Sat, 9 Mar 2024 12:13:58 +0800 Subject: [PATCH 3/6] ci: separate check task --- .github/workflows/go.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 547650638..76788ece5 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -7,6 +7,15 @@ on: branches: [ main ] jobs: + Check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Check goreleaser files + run: | + pip install --no-input pyyaml + python .github/workflows/check_goreleaser_config.py + Test: strategy: matrix: @@ -15,11 +24,6 @@ jobs: runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - - - name: Check goreleaser files - run: | - pip install --no-input pyyaml - python .github/workflows/check_goreleaser_config.py - name: Set up Go uses: actions/setup-go@v5 From 724c142b851c34b888230e162fccac4647e74303 Mon Sep 17 00:00:00 2001 From: Li Jie Date: Sat, 9 Mar 2024 12:33:49 +0800 Subject: [PATCH 4/6] ci: ignore VERSION file when checking goreleaser config --- .github/workflows/check_goreleaser_config.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check_goreleaser_config.py b/.github/workflows/check_goreleaser_config.py index b99d9db84..213d3155a 100644 --- a/.github/workflows/check_goreleaser_config.py +++ b/.github/workflows/check_goreleaser_config.py @@ -2,7 +2,8 @@ import subprocess import yaml -files = [f for f in os.listdir('.') if not f.startswith(".")] +files = [f for f in os.listdir('.') if not f.startswith( + ".") and f not in ["VERSION"]] files.sort() # filter out the files that are ignored by git files = [f for f in files if subprocess.call( From 4e86df5b9cf334e81a0066336cf88ac750c68766 Mon Sep 17 00:00:00 2001 From: Li Jie Date: Sat, 9 Mar 2024 12:47:54 +0800 Subject: [PATCH 5/6] ci: update fury uploading --- .github/workflows/release-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml index d24eef531..4e972682a 100644 --- a/.github/workflows/release-build.yml +++ b/.github/workflows/release-build.yml @@ -69,7 +69,7 @@ jobs: - name: Upload deb/rpm to Fury.io if: env.IS_PRERELEASE != 'true' run: | - for file in dist/*.{deb,rpm} + for file in .dist/*.{deb,rpm} do echo "Uploading $file to Fury.io" CODE=`curl --write-out '%{http_code}' --output /dev/null -sS -F package=@$file https://$FURY_TOKEN@push.fury.io/$GITHUB_REPOSITORY_OWNER/` From cdc9e083bfc4bb44878e3803d1d690ea22e010d8 Mon Sep 17 00:00:00 2001 From: Li Jie Date: Sat, 9 Mar 2024 16:04:38 +0800 Subject: [PATCH 6/6] ci: fix env var format --- .github/workflows/check_goreleaser_config.py | 2 +- .goreleaser.yaml | 60 ++++++++++---------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/.github/workflows/check_goreleaser_config.py b/.github/workflows/check_goreleaser_config.py index 213d3155a..ecd888446 100644 --- a/.github/workflows/check_goreleaser_config.py +++ b/.github/workflows/check_goreleaser_config.py @@ -35,7 +35,7 @@ print("Update .goreleaser.yaml in the nfpms section:") for f in files: print(f" - src: \"{f}\"") - print(f" dst: \"/usr/lib/{{ .ProjectName }}/{f}\"") + print(f" dst: \"/usr/lib/{{{{ .ProjectName }}}}/{f}\"") if failed: exit(1) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 3febbf374..056f1ef7b 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -148,65 +148,65 @@ nfpms: contents: # source folder - src: "LICENSE" - dst: "/usr/lib/{ .ProjectName }/LICENSE" + dst: "/usr/lib/{{ .ProjectName }}/LICENSE" - src: "Makefile" - dst: "/usr/lib/{ .ProjectName }/Makefile" + dst: "/usr/lib/{{ .ProjectName }}/Makefile" - src: "README.md" - dst: "/usr/lib/{ .ProjectName }/README.md" + dst: "/usr/lib/{{ .ProjectName }}/README.md" - src: "_gendeps.go" - dst: "/usr/lib/{ .ProjectName }/_gendeps.go" + dst: "/usr/lib/{{ .ProjectName }}/_gendeps.go" - src: "all.bash" - dst: "/usr/lib/{ .ProjectName }/all.bash" + dst: "/usr/lib/{{ .ProjectName }}/all.bash" - src: "all.bat" - dst: "/usr/lib/{ .ProjectName }/all.bat" + dst: "/usr/lib/{{ .ProjectName }}/all.bat" - src: "ast" - dst: "/usr/lib/{ .ProjectName }/ast" + dst: "/usr/lib/{{ .ProjectName }}/ast" - src: "build_install_run.go" - dst: "/usr/lib/{ .ProjectName }/build_install_run.go" + dst: "/usr/lib/{{ .ProjectName }}/build_install_run.go" - src: "builtin" - dst: "/usr/lib/{ .ProjectName }/builtin" + dst: "/usr/lib/{{ .ProjectName }}/builtin" - src: "cl" - dst: "/usr/lib/{ .ProjectName }/cl" + dst: "/usr/lib/{{ .ProjectName }}/cl" - src: "cmd" - dst: "/usr/lib/{ .ProjectName }/cmd" + dst: "/usr/lib/{{ .ProjectName }}/cmd" - src: "doc" - dst: "/usr/lib/{ .ProjectName }/doc" + dst: "/usr/lib/{{ .ProjectName }}/doc" - src: "env" - dst: "/usr/lib/{ .ProjectName }/env" + dst: "/usr/lib/{{ .ProjectName }}/env" - src: "format" - dst: "/usr/lib/{ .ProjectName }/format" + dst: "/usr/lib/{{ .ProjectName }}/format" - src: "gengo.go" - dst: "/usr/lib/{ .ProjectName }/gengo.go" + dst: "/usr/lib/{{ .ProjectName }}/gengo.go" - src: "go.mod" - dst: "/usr/lib/{ .ProjectName }/go.mod" + dst: "/usr/lib/{{ .ProjectName }}/go.mod" - src: "go.sum" - dst: "/usr/lib/{ .ProjectName }/go.sum" + dst: "/usr/lib/{{ .ProjectName }}/go.sum" - src: "imp.go" - dst: "/usr/lib/{ .ProjectName }/imp.go" + dst: "/usr/lib/{{ .ProjectName }}/imp.go" - src: "load.go" - dst: "/usr/lib/{ .ProjectName }/load.go" + dst: "/usr/lib/{{ .ProjectName }}/load.go" - src: "make.bash" - dst: "/usr/lib/{ .ProjectName }/make.bash" + dst: "/usr/lib/{{ .ProjectName }}/make.bash" - src: "make.bat" - dst: "/usr/lib/{ .ProjectName }/make.bat" + dst: "/usr/lib/{{ .ProjectName }}/make.bat" - src: "outline.go" - dst: "/usr/lib/{ .ProjectName }/outline.go" + dst: "/usr/lib/{{ .ProjectName }}/outline.go" - src: "parser" - dst: "/usr/lib/{ .ProjectName }/parser" + dst: "/usr/lib/{{ .ProjectName }}/parser" - src: "printer" - dst: "/usr/lib/{ .ProjectName }/printer" + dst: "/usr/lib/{{ .ProjectName }}/printer" - src: "scanner" - dst: "/usr/lib/{ .ProjectName }/scanner" + dst: "/usr/lib/{{ .ProjectName }}/scanner" - src: "test" - dst: "/usr/lib/{ .ProjectName }/test" + dst: "/usr/lib/{{ .ProjectName }}/test" - src: "testdata" - dst: "/usr/lib/{ .ProjectName }/testdata" + dst: "/usr/lib/{{ .ProjectName }}/testdata" - src: "tidy.go" - dst: "/usr/lib/{ .ProjectName }/tidy.go" + dst: "/usr/lib/{{ .ProjectName }}/tidy.go" - src: "token" - dst: "/usr/lib/{ .ProjectName }/token" + dst: "/usr/lib/{{ .ProjectName }}/token" - src: "x" - dst: "/usr/lib/{ .ProjectName }/x" + dst: "/usr/lib/{{ .ProjectName }}/x" # symlinks to binaries - src: "/usr/lib/{{ .ProjectName }}/bin/gop" dst: /usr/bin/gop