From 4b4c507653417d29cd4b77da1e3dee1bbb1253fc Mon Sep 17 00:00:00 2001 From: qwqcode Date: Wed, 2 Oct 2024 23:34:29 +0800 Subject: [PATCH 01/13] feat(build): add rpm build workflow to github actions --- .copr/Makefile | 4 +++ .copr/artalk.spec | 0 .copr/changelog | 0 .github/workflows/build-rpm.yml | 49 +++++++++++++++++++++++++++++++++ .github/workflows/build.yml | 10 +++++++ .github/workflows/release.yml | 9 ++++++ 6 files changed, 72 insertions(+) create mode 100644 .copr/Makefile create mode 100644 .copr/artalk.spec create mode 100644 .copr/changelog create mode 100644 .github/workflows/build-rpm.yml diff --git a/.copr/Makefile b/.copr/Makefile new file mode 100644 index 000000000..56d95f484 --- /dev/null +++ b/.copr/Makefile @@ -0,0 +1,4 @@ +srpm: + dnf -y install xxx + # 创建 vendor.tar.gz + # spec 打包 diff --git a/.copr/artalk.spec b/.copr/artalk.spec new file mode 100644 index 000000000..e69de29bb diff --git a/.copr/changelog b/.copr/changelog new file mode 100644 index 000000000..e69de29bb diff --git a/.github/workflows/build-rpm.yml b/.github/workflows/build-rpm.yml new file mode 100644 index 000000000..dee3427e6 --- /dev/null +++ b/.github/workflows/build-rpm.yml @@ -0,0 +1,49 @@ +name: Build RPM + +on: + workflow_call: + inputs: + version: + required: true + type: string + dry_run: + required: true + type: boolean + workflow_dispatch: + +jobs: + build_rpm: + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + ref: ${{ inputs.version }} + + # copr webhook trigger + - name: Trigger Copr Webhook + run: curl -X POST https://copr.fedorainfracloud.org/webhooks/trigger/12345/abcdef + + # - name: Use pnpm + # uses: pnpm/action-setup@v4 + # with: + # version: 9.10.0 + + # - name: Setup node + # uses: actions/setup-node@v4 + # with: + # node-version: 20.x + # registry-url: https://registry.npmjs.org/ + # cache: "pnpm" + + # - name: Install dependencies + # run: pnpm install --frozen-lockfile + + # - name: Build + # run: pnpm build + + # - name: Publish + # run: pnpm publish -F artalk --no-git-checks ${{ inputs.dry_run && '--dry-run' || '' }} + # env: + # NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 75f6ca622..273e9ffe8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -71,6 +71,16 @@ jobs: dry_run: ${{ inputs.dry_run || false }} secrets: inherit + # Build RPM + rpm: + if: inputs.build_items == '' || contains(inputs.build_items, 'rpm') + needs: tagging + uses: ./.github/workflows/build-rpm.yml + with: + version: ${{ needs.tagging.outputs.version }} + dry_run: ${{ inputs.dry_run || false }} + secrets: inherit + # All builds are complete done: needs: [tagging, ui, docker, app] diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 98afaac76..952837c39 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -77,6 +77,15 @@ jobs: # modify the version in docs perl -pi -e 's#"latest"(\W+)?:(\W+)?".*?"#"latest": "'${VERSION#v}'"#g' docs/docs/code/ArtalkVersion.json + # modify .copr/artalk.spec + perl -i -pe 's/Version:.*/Version: '${VERSION#v}'/g' .copr/artalk.spec + + # modify .copr/changelog + echo -e "* $(date +'%a %b %d %Y')" \ + "github-actions[bot] -" \ + "${VERSION#v}-1\n- Update to version ${VERSION#v}\n" \ + | cat - .copr/changelog > temp && mv temp .copr/changelog + - name: Print Git Diff run: git diff From 995b07fe58acf9472081396e45a4a807f4ad783b Mon Sep 17 00:00:00 2001 From: duli Date: Wed, 2 Oct 2024 23:44:40 +0800 Subject: [PATCH 02/13] initial all stuff. --- ...undefined-error-by-remove-clickhouse.patch | 27 ++++++ .copr/0002-remove-upgrade-command.patch | 24 +++++ .copr/artalk.service | 22 +++++ .copr/artalk.spec | 95 +++++++++++++++++++ .copr/artalk.sysusers | 3 + .copr/changelog | 29 ++++++ .copr/vendor-tarball.sh | 21 ++++ 7 files changed, 221 insertions(+) create mode 100644 .copr/0001-fix-go-test-ld-undefined-error-by-remove-clickhouse.patch create mode 100644 .copr/0002-remove-upgrade-command.patch create mode 100644 .copr/artalk.service create mode 100644 .copr/artalk.sysusers create mode 100755 .copr/vendor-tarball.sh diff --git a/.copr/0001-fix-go-test-ld-undefined-error-by-remove-clickhouse.patch b/.copr/0001-fix-go-test-ld-undefined-error-by-remove-clickhouse.patch new file mode 100644 index 000000000..be73fec3b --- /dev/null +++ b/.copr/0001-fix-go-test-ld-undefined-error-by-remove-clickhouse.patch @@ -0,0 +1,27 @@ +From e5ad75e3ee17331ddba32c9133eae6bbdac3fbb6 Mon Sep 17 00:00:00 2001 +From: duli +Date: Wed, 2 Oct 2024 18:26:56 +0800 +Subject: [PATCH] fix: go test ld undefined error by remove clickhouse-go + +github.com/segmentio/asm build must need go module feature, disable it +will cause ld error, due to clickhouse-go is not in use. we delete it to +fix that. +--- + vendor/github.com/go-testfixtures/testfixtures/v3/clickhouse.go | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/vendor/github.com/go-testfixtures/testfixtures/v3/clickhouse.go b/vendor/github.com/go-testfixtures/testfixtures/v3/clickhouse.go +index c01c9ee6..7f6c76a8 100644 +--- a/vendor/github.com/go-testfixtures/testfixtures/v3/clickhouse.go ++++ b/vendor/github.com/go-testfixtures/testfixtures/v3/clickhouse.go +@@ -4,7 +4,6 @@ import ( + "database/sql" + "fmt" + +- _ "github.com/ClickHouse/clickhouse-go/v2" + ) + + type clickhouse struct { +-- +2.46.2 + diff --git a/.copr/0002-remove-upgrade-command.patch b/.copr/0002-remove-upgrade-command.patch new file mode 100644 index 000000000..7d80d6146 --- /dev/null +++ b/.copr/0002-remove-upgrade-command.patch @@ -0,0 +1,24 @@ +From 79a66c91db582db6c740e343c707d4967117f762 Mon Sep 17 00:00:00 2001 +From: duli +Date: Wed, 2 Oct 2024 18:46:32 +0800 +Subject: [PATCH] remove upgrade command + +--- + cmd/base.go | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/cmd/base.go b/cmd/base.go +index a3a3a34f..44a2e468 100644 +--- a/cmd/base.go ++++ b/cmd/base.go +@@ -121,7 +121,6 @@ func (atk *ArtalkCmd) mountCommands() { + atk.addCommand(NewImportCommand(atk)) + atk.addCommand(NewConfigCommand()) + atk.addCommand(NewGenCommand()) +- atk.addCommand(NewUpgradeCommand()) + atk.addCommand(NewVersionCommand()) + } + +-- +2.46.2 + diff --git a/.copr/artalk.service b/.copr/artalk.service new file mode 100644 index 000000000..6bd92b246 --- /dev/null +++ b/.copr/artalk.service @@ -0,0 +1,22 @@ +[Unit] +Description=Artalk, A Self-hosted Comment System. +Documentation=https://artalk.js.org +After=network.target network-online.target +Requires=network-online.target + +[Service] +Type=simple +User=artalk +Group=artalk +ExecStart=/usr/bin/artalk server -w /var/lib/artalk -c /etc/artalk/artalk.yml +ExecReload=/bin/kill -s HUP $MAINPID +ExecStop=/bin/kill -s QUIT $MAINPID +TimeoutStopSec=5s +LimitNOFILE=1048576 +LimitNPROC=512 +PrivateTmp=true +ProtectSystem=full +AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE + +[Install] +WantedBy=multi-user.target diff --git a/.copr/artalk.spec b/.copr/artalk.spec index e69de29bb..31d7a2e4d 100644 --- a/.copr/artalk.spec +++ b/.copr/artalk.spec @@ -0,0 +1,95 @@ +%global goipath github.com/artalkjs/artalk/v2 +Version: 2.9.1 +%gometa -f +Name: artalk +Release: %autorelease +Summary: A Self-hosted Comment System +License: MIT +URL: https://artalk.js.org/ +Source0: %{name}-%{version}-vendored.tar.gz +# track this script +Source1: vendor-tarball.sh +Source2: https://github.com/ArtalkJS/Artalk/releases/download/v%{version}/artalk_ui.tar.gz +Source3: artalk.sysusers +Source4: artalk.service +Patch1: 0001-fix-go-test-ld-undefined-error-by-remove-clickhouse.patch +Patch2: 0002-remove-upgrade-command.patch +BuildRequires: systemd-rpm-macros +%{?systemd_requires} +%{?sysusers_requires_compat} + + +%description +Artalk is an intuitive yet feature-rich comment system, ready for immediate deployment into any blog, website, or web application. + + +%gopkg + + +%prep +%autosetup -p1 +tar --strip-components=1 -xzf %{SOURCE2} --directory=public +%goprep -k -e +chmod -Rf a+rX,u+w,g-w,o-w . + + +%build +%gobuild -o %{gobuilddir}/bin/artalk %{goipath} + + +%install +%gopkginstall + +# command +install -m 0755 -vd %{buildroot}%{_bindir} +install -m 0755 -vp %{gobuilddir}/bin/* %{buildroot}%{_bindir}/ + +# sysusers +install -p -D -m 0644 %{SOURCE3} %{buildroot}%{_sysusersdir}/%{name}.conf + +# data directory (work dir) +install -d -m 0750 %{buildroot}%{_sharedstatedir}/artalk + +# config +install -D -p -m 0644 ./conf/artalk.example.yml %{buildroot}%{_sysconfdir}/artalk/artalk.yml + +# systemd units +install -D -p -m 0644 %{SOURCE4} %{buildroot}%{_unitdir}/artalk.service + + +%check +%gocheck + + +%pre +%sysusers_create_compat %{SOURCE3} + + +%post +%systemd_post artalk.service + + +%preun +%systemd_preun artalk.service + + +%postun +%systemd_postun_with_restart artalk.service + + +%files +%doc CONTRIBUTING.md README.md +%license LICENSE +%{_bindir}/artalk +%{_unitdir}/artalk.service +%{_sysusersdir}/%{name}.conf +%dir %{_sysconfdir}/artalk +%config(noreplace) %{_sysconfdir}/artalk/artalk.yml +%attr(0750,artalk,artalk) %dir %{_sharedstatedir}/artalk + + +%gopkgfiles + + +%changelog +%autochangelog diff --git a/.copr/artalk.sysusers b/.copr/artalk.sysusers new file mode 100644 index 000000000..05f1a99c5 --- /dev/null +++ b/.copr/artalk.sysusers @@ -0,0 +1,3 @@ +#Type Name ID GECOS Home directory Shell +u artalk - "Artalk server" /var/lib/artalk /sbin/nologin +g artalk - - - - diff --git a/.copr/changelog b/.copr/changelog index e69de29bb..ecf1f1339 100644 --- a/.copr/changelog +++ b/.copr/changelog @@ -0,0 +1,29 @@ +* Wed Oct 02 2024 duli - 2.9.1-10 +- remove upgrade command + +* Wed Oct 02 2024 duli - 2.9.1-9 +- add package testing + +* Wed Oct 02 2024 duli - 2.9.1-8 +- reuse %%gobuild instead of go build -mod=vendor + +* Wed Oct 02 2024 duli - 2.9.1-7 +- change the way vendor artalk + +* Tue Oct 01 2024 duli - 2.9.1-6 +- reorganize spec file + +* Tue Oct 01 2024 duli - 2.9.1-5 +- add systemd service + +* Tue Oct 01 2024 duli - 2.9.1-4 +- add config file + +* Tue Oct 01 2024 duli - 2.9.1-3 +- fix: ui files lack + +* Tue Oct 01 2024 duli - 2.9.1-2 +- add artalk user and group + +* Mon Sep 30 2024 duli - 2.9.1-1 +- initial commit \ No newline at end of file diff --git a/.copr/vendor-tarball.sh b/.copr/vendor-tarball.sh new file mode 100755 index 000000000..774983dcd --- /dev/null +++ b/.copr/vendor-tarball.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env sh +tag=$1 +name=artalk + +if [[ -z $tag ]]; then + echo "This script requires the tag as an argument." + exit 1 +fi + +set -euo pipefail + +version=${tag#v} + +echo "Using version: $version" + +git -c advice.detachedHead=false clone --branch $tag --depth 1 https://github.com/artalkjs/artalk/ $name-$version +pushd $name-$version +GOPROXY='https://proxy.golang.org,direct' go mod vendor +popd +tar --exclude .git -czf $name-$version-vendored.tar.gz $name-$version +rm -rf $name-$version From 06fa6f55667d37010f126cff4db75141092f58ab Mon Sep 17 00:00:00 2001 From: qwqcode Date: Wed, 2 Oct 2024 23:52:42 +0800 Subject: [PATCH 03/13] update build-rpm.yml --- .github/workflows/build-rpm.yml | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/.github/workflows/build-rpm.yml b/.github/workflows/build-rpm.yml index dee3427e6..9ad671557 100644 --- a/.github/workflows/build-rpm.yml +++ b/.github/workflows/build-rpm.yml @@ -21,29 +21,5 @@ jobs: with: ref: ${{ inputs.version }} - # copr webhook trigger - - name: Trigger Copr Webhook - run: curl -X POST https://copr.fedorainfracloud.org/webhooks/trigger/12345/abcdef - - # - name: Use pnpm - # uses: pnpm/action-setup@v4 - # with: - # version: 9.10.0 - - # - name: Setup node - # uses: actions/setup-node@v4 - # with: - # node-version: 20.x - # registry-url: https://registry.npmjs.org/ - # cache: "pnpm" - - # - name: Install dependencies - # run: pnpm install --frozen-lockfile - - # - name: Build - # run: pnpm build - - # - name: Publish - # run: pnpm publish -F artalk --no-git-checks ${{ inputs.dry_run && '--dry-run' || '' }} - # env: - # NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + - name: Trigger Copr Build Webhook + run: curl -X POST ${{ secrets.COPR_BUILD_WEBHOOK_URL }}/artalk From 187a6dde95e5d1b3b6b6554a6b15c803dfc2c58a Mon Sep 17 00:00:00 2001 From: qwqcode Date: Thu, 3 Oct 2024 01:52:43 +0800 Subject: [PATCH 04/13] feat(config): enhance config file and data dir retrieval - Add xdg package for XDG base directory support - Update RetrieveConfigFile to search in XDG_CONFIG_HOME and /etc - Add RetrieveDataDir to find data directory in XDG_DATA_HOME and /var/lib - Improve comments for better understanding of search order --- cmd/base.go | 53 ++++++++++++++++++++++++++++++++++------- go.mod | 1 + go.sum | 2 ++ internal/config/base.go | 43 +++++++++++++++++++++++++++++---- internal/utils/fs.go | 4 ++++ 5 files changed, 91 insertions(+), 12 deletions(-) diff --git a/cmd/base.go b/cmd/base.go index a3a3a34f5..acd2519cf 100644 --- a/cmd/base.go +++ b/cmd/base.go @@ -4,11 +4,14 @@ import ( "fmt" "os" "os/signal" + "path" "syscall" + "github.com/adrg/xdg" "github.com/artalkjs/artalk/v2/internal/config" "github.com/artalkjs/artalk/v2/internal/core" "github.com/artalkjs/artalk/v2/internal/log" + "github.com/artalkjs/artalk/v2/internal/utils" "github.com/fatih/color" "github.com/spf13/cobra" ) @@ -64,11 +67,11 @@ func New() *ArtalkCmd { // Parse base flags cmd.eagerParseFlags() - // Change work directory - if cmd.workDir != "" { - if err := os.Chdir(cmd.workDir); err != nil { - log.Fatal("Working directory change error: ", err) - } + // Init data directory (work directory) + if workDir, err := initDataDir(cmd.workDir); err == nil { + cmd.workDir = workDir + } else { + log.Fatal("Data directory fail: ", err) } return cmd @@ -167,16 +170,50 @@ func (atk *ArtalkCmd) Launch() error { return nil } +func initDataDir(workDir string) (string, error) { + // If work directory is not specified, try to find it + if workDir == "" { + // If `data` in current directory exists, not change work directory + if utils.CheckDirExist("./data") { + // log.Warn("[DEPRECATED] The `data` directory is deprecated, please move to `~/.local/share/artalk/data`") + return "", nil + } + + // Retrieve data directory assuming it's already exists + workDir = config.RetrieveDataDir() + } + + // Create new data directory if not exists + if workDir == "" { + // default data path is `~/.local/share/artalk` + workDir = path.Join(xdg.DataHome, "artalk") + if err := utils.EnsureDir(workDir); err != nil { + return "", fmt.Errorf("data directory creation error: %v", err) + } + } + + // Change work directory + if workDir != "" { + if err := os.Chdir(workDir); err != nil { + return "", fmt.Errorf("working directory change error: %v", err) + } + } + + return workDir, nil +} + // Create new config instance by specific config filename func getConfig(cfgFile string) (*config.Config, error) { - // Retrieve config file by default names when specific filename is empty + // If config file is not specified, try to find it if cfgFile == "" { + // Retrieve config file assuming it's already exists cfgFile = config.RetrieveConfigFile() } - // Generate new config file when retrieve failed + // Generate new config file if not exists if cfgFile == "" { - cfgFile = config.CONF_DEFAULT_FILENAMES[0] + // default config path is `~/.config/artalk/artalk.yml` + cfgFile = path.Join(xdg.ConfigHome, "artalk", config.CONF_DEFAULT_FILENAMES[0]) core.Gen("config", cfgFile, false) } diff --git a/go.mod b/go.mod index 3127244f2..a56d0f6e9 100644 --- a/go.mod +++ b/go.mod @@ -62,6 +62,7 @@ require ( github.com/ClickHouse/clickhouse-go/v2 v2.28.3 // indirect github.com/KyleBanks/depth v1.2.1 // indirect github.com/VividCortex/ewma v1.2.0 // indirect + github.com/adrg/xdg v0.5.0 // indirect github.com/andybalholm/brotli v1.1.0 // indirect github.com/aymerick/douceur v0.2.0 // indirect github.com/beorn7/perks v1.0.1 // indirect diff --git a/go.sum b/go.sum index 4a6f13af6..f7ec0f502 100644 --- a/go.sum +++ b/go.sum @@ -37,6 +37,8 @@ github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow= github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4= +github.com/adrg/xdg v0.5.0 h1:dDaZvhMXatArP1NPHhnfaQUqWBLBsmx1h1HXQdMoFCY= +github.com/adrg/xdg v0.5.0/go.mod h1:dDdY4M4DF9Rjy4kHPeNL+ilVF+p2lK8IdM9/rTSGcI4= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= diff --git a/internal/config/base.go b/internal/config/base.go index 9a6715585..550ba9cf5 100644 --- a/internal/config/base.go +++ b/internal/config/base.go @@ -5,10 +5,12 @@ package config import ( "fmt" "os" + "path" "strconv" "strings" "unicode" + "github.com/adrg/xdg" "github.com/artalkjs/artalk/v2/internal/config/env_provider" "github.com/artalkjs/artalk/v2/internal/log" "github.com/artalkjs/artalk/v2/internal/utils" @@ -242,11 +244,44 @@ func (conf *Config) historyPatch() { } } -// 尝试查找配置文件 +// Try to find the configuration file +// +// The order of the search is: +// 1. Current directory (./artalk.yml) +// 2. Current subdirectory (./data/artalk.yml) +// 3. XDG_CONFIG_HOME (~/.config/artalk.yml) +// 4. /etc/artalk.yml (for linux packing version) func RetrieveConfigFile() string { - for _, v := range CONF_DEFAULT_FILENAMES { - if utils.CheckFileExist(v) { - return v + lookupDirs := []string{".", "./data", xdg.ConfigHome, "/etc"} + paths := []string{} + for _, dir := range lookupDirs { + for _, name := range CONF_DEFAULT_FILENAMES { + if dir == "." || dir == "./data" { + paths = append(paths, path.Join(dir, name)) + } else { + paths = append(paths, path.Join(dir, "artalk", name)) + } + } + } + for _, path := range paths { + if utils.CheckFileExist(path) { + return path + } + } + return "" +} + +// Try to find the data directory (work directory) +// +// The order of the search is: +// 1. XDG_DATA_HOME (~/.local/share) +// 2. /var/lib (for linux packing version) +func RetrieveDataDir() string { + lookupDirs := []string{xdg.DataHome, "/var/lib"} + for _, dir := range lookupDirs { + dir = path.Join(dir, "artalk") + if utils.CheckDirExist(dir) { + return dir } } return "" diff --git a/internal/utils/fs.go b/internal/utils/fs.go index 1562acb13..ce699c368 100644 --- a/internal/utils/fs.go +++ b/internal/utils/fs.go @@ -11,3 +11,7 @@ func CheckFileExist(path string) bool { _, err := os.Stat(path) return err == nil } + +func CheckDirExist(path string) bool { + return CheckFileExist(path) +} From ba5ede7e4a02bfe8f196b8f3bea5f3949020e503 Mon Sep 17 00:00:00 2001 From: duli Date: Thu, 3 Oct 2024 15:09:49 +0800 Subject: [PATCH 05/13] add Makefile and improve vendor-tarball.sh --- .copr/Makefile | 12 +++++++++--- .copr/vendor-tarball.sh | 31 ++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/.copr/Makefile b/.copr/Makefile index 56d95f484..07d9fce27 100644 --- a/.copr/Makefile +++ b/.copr/Makefile @@ -1,4 +1,10 @@ +tag= + srpm: - dnf -y install xxx - # 创建 vendor.tar.gz - # spec 打包 + dnf -y install git rpmdevtools golang rpmautospec rpkg + $(eval tag=$(shell git tag -l 'v*' --sort=-v:refname | head -n 1)) + @echo $(tag) + spectool -g artalk.spec + ./vendor-tarball.sh ${tag} + rpmautospec process-distgit artalk.spec artalk.spec + rpkg srpm --spec artalk.spec --outdir=$(outdir) diff --git a/.copr/vendor-tarball.sh b/.copr/vendor-tarball.sh index 774983dcd..39d9e5ff9 100755 --- a/.copr/vendor-tarball.sh +++ b/.copr/vendor-tarball.sh @@ -10,12 +10,33 @@ fi set -euo pipefail version=${tag#v} - echo "Using version: $version" -git -c advice.detachedHead=false clone --branch $tag --depth 1 https://github.com/artalkjs/artalk/ $name-$version -pushd $name-$version +rm -rf "$name-$version" + +# Clone the repository +git -c advice.detachedHead=false clone --branch "$tag" --depth 1 https://github.com/artalkjs/artalk/ "$name-$version" +pushd "$name-$version" + +# Vendor dependencies GOPROXY='https://proxy.golang.org,direct' go mod vendor popd -tar --exclude .git -czf $name-$version-vendored.tar.gz $name-$version -rm -rf $name-$version + +# More reproducible! +TARFLAGS=( + --exclude .git + --sort=name + --format=posix + --pax-option=delete=atime,delete=ctime + --clamp-mtime + --mtime='1970-01-01 00:00:00 UTC' + --numeric-owner + --owner=0 + --group=0 + --mode=go+u,go-w +) + +tar "${TARFLAGS[@]}" -czf "$name-$version-vendored.tar.gz" "$name-$version" + +# Clean up the temporary directory +rm -rf "$name-$version" From 76dc9025e4c6dbe3c985af101b688adf4bcb81d7 Mon Sep 17 00:00:00 2001 From: duli Date: Thu, 3 Oct 2024 15:37:46 +0800 Subject: [PATCH 06/13] fix: %autochangelog macro not work --- .copr/Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.copr/Makefile b/.copr/Makefile index 07d9fce27..b0ff4d7a9 100644 --- a/.copr/Makefile +++ b/.copr/Makefile @@ -6,5 +6,10 @@ srpm: @echo $(tag) spectool -g artalk.spec ./vendor-tarball.sh ${tag} - rpmautospec process-distgit artalk.spec artalk.spec + git stash # make sure workspace is empty. + cp changelog artalk.spec ../ + git add ../changelog ../artalk.spec && git commit -m "for rpmautospec [skip changelog]" + rpmautospec process-distgit ../artalk.spec artalk.spec + git stash pop # pop it! + mkdir -p $(outdir) rpkg srpm --spec artalk.spec --outdir=$(outdir) From 6c3c25c29e995cf746e532761fa30ee5db17e630 Mon Sep 17 00:00:00 2001 From: duli Date: Thu, 3 Oct 2024 15:47:05 +0800 Subject: [PATCH 07/13] add new changelog --- .copr/changelog | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.copr/changelog b/.copr/changelog index ecf1f1339..778780964 100644 --- a/.copr/changelog +++ b/.copr/changelog @@ -1,3 +1,6 @@ +* Wed Oct 02 2024 duli - 2.9.1-11 +- improve vendor-tarball.sh to make it reproducible + * Wed Oct 02 2024 duli - 2.9.1-10 - remove upgrade command From cc5e62c03b559b73aad985bc7388fca228df98c6 Mon Sep 17 00:00:00 2001 From: duli Date: Thu, 3 Oct 2024 16:23:39 +0800 Subject: [PATCH 08/13] try to fix Makefile --- .copr/Makefile | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.copr/Makefile b/.copr/Makefile index b0ff4d7a9..a5ab84fb3 100644 --- a/.copr/Makefile +++ b/.copr/Makefile @@ -1,15 +1,19 @@ +src := $(shell pwd)/.copr tag= -srpm: - dnf -y install git rpmdevtools golang rpmautospec rpkg +srpm: dep + pushd $(src) $(eval tag=$(shell git tag -l 'v*' --sort=-v:refname | head -n 1)) @echo $(tag) spectool -g artalk.spec - ./vendor-tarball.sh ${tag} + ./vendor-tarball.sh $(tag) git stash # make sure workspace is empty. cp changelog artalk.spec ../ git add ../changelog ../artalk.spec && git commit -m "for rpmautospec [skip changelog]" rpmautospec process-distgit ../artalk.spec artalk.spec git stash pop # pop it! - mkdir -p $(outdir) rpkg srpm --spec artalk.spec --outdir=$(outdir) + popd + +dep: + dnf -y install git rpmdevtools golang rpmautospec rpkg From 06ccd195582617be0ecff9592e5bf3910f48af86 Mon Sep 17 00:00:00 2001 From: duli Date: Thu, 3 Oct 2024 16:59:36 +0800 Subject: [PATCH 09/13] fix: Makefile and create copr_script.sh --- .copr/Makefile | 20 ++------------------ .copr/copr_script.sh | 33 +++++++++++++++++++++++++++++++++ .copr/vendor-tarball.sh | 2 +- 3 files changed, 36 insertions(+), 19 deletions(-) create mode 100755 .copr/copr_script.sh diff --git a/.copr/Makefile b/.copr/Makefile index a5ab84fb3..bd04fd380 100644 --- a/.copr/Makefile +++ b/.copr/Makefile @@ -1,19 +1,3 @@ -src := $(shell pwd)/.copr -tag= - -srpm: dep - pushd $(src) - $(eval tag=$(shell git tag -l 'v*' --sort=-v:refname | head -n 1)) - @echo $(tag) - spectool -g artalk.spec - ./vendor-tarball.sh $(tag) - git stash # make sure workspace is empty. - cp changelog artalk.spec ../ - git add ../changelog ../artalk.spec && git commit -m "for rpmautospec [skip changelog]" - rpmautospec process-distgit ../artalk.spec artalk.spec - git stash pop # pop it! - rpkg srpm --spec artalk.spec --outdir=$(outdir) - popd - -dep: +srpm: dnf -y install git rpmdevtools golang rpmautospec rpkg + .copr/copr_script.sh $(outdir) diff --git a/.copr/copr_script.sh b/.copr/copr_script.sh new file mode 100755 index 000000000..c6823fe98 --- /dev/null +++ b/.copr/copr_script.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env sh + +set -euo pipefail + +outdir=$1 +echo "Outdir: $outdir" + +tag=$(git tag -l 'v*' --sort=-v:refname | head -n 1) +echo "Using tag: $tag" + +pushd .copr + +# Download source +spectool -g artalk.spec + +rm -rf "artalk-${tag#v}-vendored.tar.gz" +./vendor-tarball.sh $tag + +# Parse %autorelease and %autochangelog +git stash +cp changelog artalk.spec ../ +git add ../changelog ../artalk.spec +git commit -m "for rpmautospec [skip changelog]" +rpmautospec process-distgit ../artalk.spec artalk.spec +if git stash list | grep -q 'stash@'; then + git stash pop +fi + +# Generate srpm +mkdir -p $outdir +rpkg srpm --spec artalk.spec --outdir=$outdir + +popd diff --git a/.copr/vendor-tarball.sh b/.copr/vendor-tarball.sh index 39d9e5ff9..41bdc2d7d 100755 --- a/.copr/vendor-tarball.sh +++ b/.copr/vendor-tarball.sh @@ -36,7 +36,7 @@ TARFLAGS=( --mode=go+u,go-w ) -tar "${TARFLAGS[@]}" -czf "$name-$version-vendored.tar.gz" "$name-$version" +tar "${TARFLAGS[@]}" -czvf "$name-$version-vendored.tar.gz" "$name-$version" # Clean up the temporary directory rm -rf "$name-$version" From 39079ee4ec343d4948464b4a3359801201b504bd Mon Sep 17 00:00:00 2001 From: duli Date: Thu, 3 Oct 2024 17:40:03 +0800 Subject: [PATCH 10/13] fix: commit does not have author in copr --- .copr/copr_script.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.copr/copr_script.sh b/.copr/copr_script.sh index c6823fe98..ae7b65438 100755 --- a/.copr/copr_script.sh +++ b/.copr/copr_script.sh @@ -16,6 +16,10 @@ spectool -g artalk.spec rm -rf "artalk-${tag#v}-vendored.tar.gz" ./vendor-tarball.sh $tag +# fix for Please tell me who you are. +git config --global user.email "nonexist@artalk.com" +git config --global user.name "artalk" + # Parse %autorelease and %autochangelog git stash cp changelog artalk.spec ../ From 0ded76a0d844e1c4c3e5cbe38f8daf7f3cbd4711 Mon Sep 17 00:00:00 2001 From: duli Date: Thu, 3 Oct 2024 18:00:04 +0800 Subject: [PATCH 11/13] fix: copr fails to clean up symlinks during exit --- .copr/copr_script.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.copr/copr_script.sh b/.copr/copr_script.sh index ae7b65438..9a2907727 100755 --- a/.copr/copr_script.sh +++ b/.copr/copr_script.sh @@ -31,7 +31,7 @@ if git stash list | grep -q 'stash@'; then fi # Generate srpm -mkdir -p $outdir -rpkg srpm --spec artalk.spec --outdir=$outdir - +mkdir -p result_srpm +rpkg srpm --spec artalk.spec --outdir=result_srpm +cp -r result_srpm/artalk*.src.rpm $outdir popd From f5a4d4946bbc2d70fe8bdffdd6405d829078c292 Mon Sep 17 00:00:00 2001 From: duli Date: Thu, 3 Oct 2024 18:44:58 +0800 Subject: [PATCH 12/13] change changelog --- .copr/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.copr/changelog b/.copr/changelog index 778780964..81fa6914f 100644 --- a/.copr/changelog +++ b/.copr/changelog @@ -1,4 +1,4 @@ -* Wed Oct 02 2024 duli - 2.9.1-11 +* Thu Oct 03 2024 duli - 2.9.1-11 - improve vendor-tarball.sh to make it reproducible * Wed Oct 02 2024 duli - 2.9.1-10 From 16876e4ce981ff1859ad87df767c8ba2c839c836 Mon Sep 17 00:00:00 2001 From: duli Date: Fri, 4 Oct 2024 00:00:19 +0800 Subject: [PATCH 13/13] refactor: move rpm build contents to dist/fedora branch --- ...undefined-error-by-remove-clickhouse.patch | 27 ------ .copr/0002-remove-upgrade-command.patch | 24 ----- .copr/Makefile | 3 - .copr/artalk.service | 22 ----- .copr/artalk.spec | 95 ------------------- .copr/artalk.sysusers | 3 - .copr/changelog | 32 ------- .copr/copr_script.sh | 37 -------- .copr/vendor-tarball.sh | 42 -------- 9 files changed, 285 deletions(-) delete mode 100644 .copr/0001-fix-go-test-ld-undefined-error-by-remove-clickhouse.patch delete mode 100644 .copr/0002-remove-upgrade-command.patch delete mode 100644 .copr/Makefile delete mode 100644 .copr/artalk.service delete mode 100644 .copr/artalk.spec delete mode 100644 .copr/artalk.sysusers delete mode 100644 .copr/changelog delete mode 100755 .copr/copr_script.sh delete mode 100755 .copr/vendor-tarball.sh diff --git a/.copr/0001-fix-go-test-ld-undefined-error-by-remove-clickhouse.patch b/.copr/0001-fix-go-test-ld-undefined-error-by-remove-clickhouse.patch deleted file mode 100644 index be73fec3b..000000000 --- a/.copr/0001-fix-go-test-ld-undefined-error-by-remove-clickhouse.patch +++ /dev/null @@ -1,27 +0,0 @@ -From e5ad75e3ee17331ddba32c9133eae6bbdac3fbb6 Mon Sep 17 00:00:00 2001 -From: duli -Date: Wed, 2 Oct 2024 18:26:56 +0800 -Subject: [PATCH] fix: go test ld undefined error by remove clickhouse-go - -github.com/segmentio/asm build must need go module feature, disable it -will cause ld error, due to clickhouse-go is not in use. we delete it to -fix that. ---- - vendor/github.com/go-testfixtures/testfixtures/v3/clickhouse.go | 1 - - 1 file changed, 1 deletion(-) - -diff --git a/vendor/github.com/go-testfixtures/testfixtures/v3/clickhouse.go b/vendor/github.com/go-testfixtures/testfixtures/v3/clickhouse.go -index c01c9ee6..7f6c76a8 100644 ---- a/vendor/github.com/go-testfixtures/testfixtures/v3/clickhouse.go -+++ b/vendor/github.com/go-testfixtures/testfixtures/v3/clickhouse.go -@@ -4,7 +4,6 @@ import ( - "database/sql" - "fmt" - -- _ "github.com/ClickHouse/clickhouse-go/v2" - ) - - type clickhouse struct { --- -2.46.2 - diff --git a/.copr/0002-remove-upgrade-command.patch b/.copr/0002-remove-upgrade-command.patch deleted file mode 100644 index 7d80d6146..000000000 --- a/.copr/0002-remove-upgrade-command.patch +++ /dev/null @@ -1,24 +0,0 @@ -From 79a66c91db582db6c740e343c707d4967117f762 Mon Sep 17 00:00:00 2001 -From: duli -Date: Wed, 2 Oct 2024 18:46:32 +0800 -Subject: [PATCH] remove upgrade command - ---- - cmd/base.go | 1 - - 1 file changed, 1 deletion(-) - -diff --git a/cmd/base.go b/cmd/base.go -index a3a3a34f..44a2e468 100644 ---- a/cmd/base.go -+++ b/cmd/base.go -@@ -121,7 +121,6 @@ func (atk *ArtalkCmd) mountCommands() { - atk.addCommand(NewImportCommand(atk)) - atk.addCommand(NewConfigCommand()) - atk.addCommand(NewGenCommand()) -- atk.addCommand(NewUpgradeCommand()) - atk.addCommand(NewVersionCommand()) - } - --- -2.46.2 - diff --git a/.copr/Makefile b/.copr/Makefile deleted file mode 100644 index bd04fd380..000000000 --- a/.copr/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -srpm: - dnf -y install git rpmdevtools golang rpmautospec rpkg - .copr/copr_script.sh $(outdir) diff --git a/.copr/artalk.service b/.copr/artalk.service deleted file mode 100644 index 6bd92b246..000000000 --- a/.copr/artalk.service +++ /dev/null @@ -1,22 +0,0 @@ -[Unit] -Description=Artalk, A Self-hosted Comment System. -Documentation=https://artalk.js.org -After=network.target network-online.target -Requires=network-online.target - -[Service] -Type=simple -User=artalk -Group=artalk -ExecStart=/usr/bin/artalk server -w /var/lib/artalk -c /etc/artalk/artalk.yml -ExecReload=/bin/kill -s HUP $MAINPID -ExecStop=/bin/kill -s QUIT $MAINPID -TimeoutStopSec=5s -LimitNOFILE=1048576 -LimitNPROC=512 -PrivateTmp=true -ProtectSystem=full -AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE - -[Install] -WantedBy=multi-user.target diff --git a/.copr/artalk.spec b/.copr/artalk.spec deleted file mode 100644 index 31d7a2e4d..000000000 --- a/.copr/artalk.spec +++ /dev/null @@ -1,95 +0,0 @@ -%global goipath github.com/artalkjs/artalk/v2 -Version: 2.9.1 -%gometa -f -Name: artalk -Release: %autorelease -Summary: A Self-hosted Comment System -License: MIT -URL: https://artalk.js.org/ -Source0: %{name}-%{version}-vendored.tar.gz -# track this script -Source1: vendor-tarball.sh -Source2: https://github.com/ArtalkJS/Artalk/releases/download/v%{version}/artalk_ui.tar.gz -Source3: artalk.sysusers -Source4: artalk.service -Patch1: 0001-fix-go-test-ld-undefined-error-by-remove-clickhouse.patch -Patch2: 0002-remove-upgrade-command.patch -BuildRequires: systemd-rpm-macros -%{?systemd_requires} -%{?sysusers_requires_compat} - - -%description -Artalk is an intuitive yet feature-rich comment system, ready for immediate deployment into any blog, website, or web application. - - -%gopkg - - -%prep -%autosetup -p1 -tar --strip-components=1 -xzf %{SOURCE2} --directory=public -%goprep -k -e -chmod -Rf a+rX,u+w,g-w,o-w . - - -%build -%gobuild -o %{gobuilddir}/bin/artalk %{goipath} - - -%install -%gopkginstall - -# command -install -m 0755 -vd %{buildroot}%{_bindir} -install -m 0755 -vp %{gobuilddir}/bin/* %{buildroot}%{_bindir}/ - -# sysusers -install -p -D -m 0644 %{SOURCE3} %{buildroot}%{_sysusersdir}/%{name}.conf - -# data directory (work dir) -install -d -m 0750 %{buildroot}%{_sharedstatedir}/artalk - -# config -install -D -p -m 0644 ./conf/artalk.example.yml %{buildroot}%{_sysconfdir}/artalk/artalk.yml - -# systemd units -install -D -p -m 0644 %{SOURCE4} %{buildroot}%{_unitdir}/artalk.service - - -%check -%gocheck - - -%pre -%sysusers_create_compat %{SOURCE3} - - -%post -%systemd_post artalk.service - - -%preun -%systemd_preun artalk.service - - -%postun -%systemd_postun_with_restart artalk.service - - -%files -%doc CONTRIBUTING.md README.md -%license LICENSE -%{_bindir}/artalk -%{_unitdir}/artalk.service -%{_sysusersdir}/%{name}.conf -%dir %{_sysconfdir}/artalk -%config(noreplace) %{_sysconfdir}/artalk/artalk.yml -%attr(0750,artalk,artalk) %dir %{_sharedstatedir}/artalk - - -%gopkgfiles - - -%changelog -%autochangelog diff --git a/.copr/artalk.sysusers b/.copr/artalk.sysusers deleted file mode 100644 index 05f1a99c5..000000000 --- a/.copr/artalk.sysusers +++ /dev/null @@ -1,3 +0,0 @@ -#Type Name ID GECOS Home directory Shell -u artalk - "Artalk server" /var/lib/artalk /sbin/nologin -g artalk - - - - diff --git a/.copr/changelog b/.copr/changelog deleted file mode 100644 index 81fa6914f..000000000 --- a/.copr/changelog +++ /dev/null @@ -1,32 +0,0 @@ -* Thu Oct 03 2024 duli - 2.9.1-11 -- improve vendor-tarball.sh to make it reproducible - -* Wed Oct 02 2024 duli - 2.9.1-10 -- remove upgrade command - -* Wed Oct 02 2024 duli - 2.9.1-9 -- add package testing - -* Wed Oct 02 2024 duli - 2.9.1-8 -- reuse %%gobuild instead of go build -mod=vendor - -* Wed Oct 02 2024 duli - 2.9.1-7 -- change the way vendor artalk - -* Tue Oct 01 2024 duli - 2.9.1-6 -- reorganize spec file - -* Tue Oct 01 2024 duli - 2.9.1-5 -- add systemd service - -* Tue Oct 01 2024 duli - 2.9.1-4 -- add config file - -* Tue Oct 01 2024 duli - 2.9.1-3 -- fix: ui files lack - -* Tue Oct 01 2024 duli - 2.9.1-2 -- add artalk user and group - -* Mon Sep 30 2024 duli - 2.9.1-1 -- initial commit \ No newline at end of file diff --git a/.copr/copr_script.sh b/.copr/copr_script.sh deleted file mode 100755 index 9a2907727..000000000 --- a/.copr/copr_script.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env sh - -set -euo pipefail - -outdir=$1 -echo "Outdir: $outdir" - -tag=$(git tag -l 'v*' --sort=-v:refname | head -n 1) -echo "Using tag: $tag" - -pushd .copr - -# Download source -spectool -g artalk.spec - -rm -rf "artalk-${tag#v}-vendored.tar.gz" -./vendor-tarball.sh $tag - -# fix for Please tell me who you are. -git config --global user.email "nonexist@artalk.com" -git config --global user.name "artalk" - -# Parse %autorelease and %autochangelog -git stash -cp changelog artalk.spec ../ -git add ../changelog ../artalk.spec -git commit -m "for rpmautospec [skip changelog]" -rpmautospec process-distgit ../artalk.spec artalk.spec -if git stash list | grep -q 'stash@'; then - git stash pop -fi - -# Generate srpm -mkdir -p result_srpm -rpkg srpm --spec artalk.spec --outdir=result_srpm -cp -r result_srpm/artalk*.src.rpm $outdir -popd diff --git a/.copr/vendor-tarball.sh b/.copr/vendor-tarball.sh deleted file mode 100755 index 41bdc2d7d..000000000 --- a/.copr/vendor-tarball.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env sh -tag=$1 -name=artalk - -if [[ -z $tag ]]; then - echo "This script requires the tag as an argument." - exit 1 -fi - -set -euo pipefail - -version=${tag#v} -echo "Using version: $version" - -rm -rf "$name-$version" - -# Clone the repository -git -c advice.detachedHead=false clone --branch "$tag" --depth 1 https://github.com/artalkjs/artalk/ "$name-$version" -pushd "$name-$version" - -# Vendor dependencies -GOPROXY='https://proxy.golang.org,direct' go mod vendor -popd - -# More reproducible! -TARFLAGS=( - --exclude .git - --sort=name - --format=posix - --pax-option=delete=atime,delete=ctime - --clamp-mtime - --mtime='1970-01-01 00:00:00 UTC' - --numeric-owner - --owner=0 - --group=0 - --mode=go+u,go-w -) - -tar "${TARFLAGS[@]}" -czvf "$name-$version-vendored.tar.gz" "$name-$version" - -# Clean up the temporary directory -rm -rf "$name-$version"