diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 393e94f2..1392753b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -193,3 +193,40 @@ jobs: cloudsmith push rpm evilmartians/lefthook/any-distro/any-version dist/lefthook_*_arm64.rpm cloudsmith push alpine evilmartians/lefthook/alpine/any-version dist/lefthook_*_amd64.apk cloudsmith push alpine evilmartians/lefthook/alpine/any-version dist/lefthook_*_arm64.apk + + publish-aur: + needs: build + runs-on: ubuntu-latest + container: + image: archlinux:latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: actions/download-artifact@v4 + with: + name: dist + - run: tar -xvf dist.tar + + - name: Update AUR package + run: | + pacman -Syu --noconfirm + pacman -S --noconfirm openssh git ruby + + useradd -m -G wheel runner + echo "%wheel ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers + + chown -R runner:runner . + + su runner -c ' + mkdir -p ~/.ssh + echo "${{ secrets.AUR_SSH_KEY }}" > ~/.ssh/aur + chmod 600 ~/.ssh/aur + echo "Host aur.archlinux.org" >> ~/.ssh/config + echo " IdentityFile ~/.ssh/aur" >> ~/.ssh/config + echo " User aur" >> ~/.ssh/config + ssh-keyscan -H aur.archlinux.org >> ~/.ssh/known_hosts + + ruby packaging/pack.rb publish_aur + ' diff --git a/.goreleaser.yml b/.goreleaser.yml index 333a9315..b24437fb 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -93,8 +93,15 @@ archives: {{- else if eq .Arch "386" }}i386 {{- else }}{{ .Arch }}{{ end }} + +source: + enabled: true + name_template: "{{ .ProjectName }}_source" + format: "tar.gz" + checksum: - name_template: '{{ .ProjectName }}_checksums.txt' + name_template: "{{ .ProjectName }}_checksums.txt" + algorithm: sha256 snapshot: name_template: "{{ .Tag }}" diff --git a/packaging/aur/PKGBUILD b/packaging/aur/PKGBUILD new file mode 100644 index 00000000..cc81efb2 --- /dev/null +++ b/packaging/aur/PKGBUILD @@ -0,0 +1,28 @@ +# Maintainer: Lefthook + +pkgname=lefthook +pkgdesc="Git hooks manager" +pkgver=1.9.3 +pkgrel=1 +arch=('x86_64' 'aarch64') +url="https://github.com/evilmartians/lefthook" +license=('MIT') +makedepends=('go>=1.21' 'rsync') +source=("https://github.com/evilmartians/lefthook/archive/v${pkgver}.tar.gz") +sha256sums=('{{ sha256sum }}') + +build() { + cd "$pkgname-$pkgver" + go build \ + -trimpath \ + -buildmode=pie \ + -mod=readonly \ + -modcacherw \ + -ldflags "-linkmode external -extldflags \"${LDFLAGS}\"" \ + . +} + +package() { + cd "$pkgname-$pkgver" + install -Dm755 $pkgname "$pkgdir"/usr/bin/$pkgname +} diff --git a/packaging/pack.rb b/packaging/pack.rb index b8553d1f..9ebc11be 100755 --- a/packaging/pack.rb +++ b/packaging/pack.rb @@ -1,6 +1,7 @@ #!/usr/bin/env ruby require "fileutils" +require "digest" VERSION = "1.9.3" @@ -38,6 +39,7 @@ def set_version replace_in_file("npm/lefthook/package.json", /"(lefthook-.+)": "[\d.]+"/, %{"\\1": "#{VERSION}"}) replace_in_file("rubygems/lefthook.gemspec", /(spec\.version\s+= ).*/, %{\\1"#{VERSION}"}) replace_in_file("pypi/setup.py", /(version+=).*/, %{\\1'#{VERSION}',}) + replace_in_file("aur/PKGBUILD", /(pkgver+=).*/, %{\\1#{VERSION}}) end def put_readme @@ -160,6 +162,35 @@ def publish_pypi system("python -m twine upload --verbose --repository lefthook dist/*", exception: true) end + def publish_aur + aur_repo = File.join(__dir__, "lefthook-aur") + system("git clone ssh://aur@aur.archlinux.org/lefthook.git #{aur_repo}") + pkgbuild_source = File.join(__dir__, "aur", "PKGBUILD") + pkgbuild_dest = File.join(aur_repo, "PKGBUILD") + cp(pkgbuild_source, pkgbuild_dest, verbose: true) + + cd(aur_repo) + + sha256 = Digest::SHA256.new + File.open(File.join(DIST, 'lefthook_source.tar.gz'), 'rb') do |file| + while chunk = file.read(1024) # Read the file in chunks + sha256.update(chunk) + end + end + sha256sum = sha256.hexdigest + replace_in_file(pkgbuild_dest, /{{ sha256sum }}/, sha256sum) + + system("makepkg --printsrcinfo > .SRCINFO") + system("makepkg") + system("makepkg --install") + + system("git config user.name 'github-actions[bot]'") + system("git config user.email 'github-actions[bot]@users.noreply.github.com'") + system("git add PKGBUILD .SRCINFO") + system("git commit -m 'release v#{VERSION}'") + system("git push origin master") + end + def replace_in_file(filepath, regexp, value) text = File.open(filepath, "r") do |f| f.read