Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: automate aur package update #899

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
'
9 changes: 8 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down
28 changes: 28 additions & 0 deletions packaging/aur/PKGBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Maintainer: Lefthook <[email protected]>

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
}
31 changes: 31 additions & 0 deletions packaging/pack.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby

require "fileutils"
require "digest"

VERSION = "1.9.3"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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://[email protected]/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
Expand Down
Loading