Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
RiverOnVenus authored Apr 4, 2024
0 parents commit c154368
Show file tree
Hide file tree
Showing 11 changed files with 327 additions and 0 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/push_aur.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: "Update AUR"

on:
push:
schedule:
- cron: "0 0 * * 6"

jobs:
generate-matrix:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Generate matrix
id: gen-matrix
run: echo "packages=$(ls */ -d | cut -f1 -d'/' | jq -R . | jq -cs .)" >> "$GITHUB_OUTPUT"
outputs:
packages: ${{ steps.gen-matrix.outputs.packages }}

aur:
runs-on: ubuntu-latest
needs: generate-matrix
strategy:
fail-fast: false
matrix:
pkgname: ${{ fromJson(needs.generate-matrix.outputs.packages) }}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_KEY }}
known_hosts: ${{ secrets.KNOWN_HOSTS }}

- name: Check PKGBUILD
id: build-test
uses: ouuan/[email protected]
with:
path: ${{ matrix.pkgname }}

- name: Handle epoch
id: epoch
run: |
oldname="${{ steps.build-test.outputs.pkgfile }}"
newname="$(echo "$oldname" | sed -e 's/[^A-Za-z0-9._-]/_/g')"
if [[ "$oldname" != "$newname" ]]; then
mv "$oldname" "$newname"
fi
echo "pkgfile=$newname" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.pkgname }}-${{ github.run_id }}
path: ${{ steps.epoch.outputs.pkgfile }}

- name: Clone AUR and update
run: |
message="$(git log -n1 --pretty='%B' "${{ matrix.pkgname }}")"
git clone ssh://[email protected]/${{ matrix.pkgname }}.git ../aur
shopt -s dotglob
shopt -s extglob
rm ../aur/!(.git|.|..) || true
cp -r ${{ matrix.pkgname }}/* ../aur
cd ../aur
git config user.name "GitHub Action"
git config user.email "[email protected]"
git add -A
escape() {
local content="$1"
content="${content//'%'/'%25'}"
content="${content//$'\n'/'%0A'}"
content="${content//$'\r'/'%0D'}"
echo "$content"
}
git diff-index @ --exit-code --quiet || ( git commit -m "Update from GitHub Actions: $message
https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}" && echo "::warning::Pushed to AUR:%0A$(escape "$message")" )
git push
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*/*.tar
*/*.gz
*/*.part
*/pkg
*/src
*/*.pkg.*
.SRCINFO
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020-2021 Yufan You

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# AUR-template

[Example](https://github.com/ouuan/AUR-packages)

Manage AUR packages in a GitHub repository, with:

- CI tests to build the packages in a clean environment, on every push, and also scheduled.
- Auto publish to AUR after CI tests are passed.
- Upload the packages built in the CI tests to Artifacts.
- Scripts to add a new package/update a package.
- Auto-generated `.SRCINFO`.
- Warnings provided by `namcap` in the GitHub Actions runs.

## Requirements

The following packages are required in order to use the `*.sh` tools:

```bash
sudo pacman -S --needed pacman-contrib fzf bat exa
```

## Get Started

1. Clone this repository.
2. Change the maintainer info in [`config`](config).
3. Remove the [example](example) directory.
4. Remove things in README except for the [Template](#template) section.
5. On GitHub, [set the secrets](https://github.com/shimataro/ssh-key-action#usage).

To add/update a package, modify it in this repository, and push. All other things will be managed by GitHub Actions.

## Template

This repository is based on [ouuan/AUR-template](https://github.com/ouuan/AUR-template).
16 changes: 16 additions & 0 deletions adopt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -eo pipefail

if [[ -n "$1" ]]; then
pkgname="$1"
else
read -rp "pkgname? " pkgname
fi

source config
git clone "ssh://[email protected]/$pkgname.git"
cd "$pkgname"
rm -rf .git .SRCINFO
sed -i "s/# Maintainer/# Contributor/g" PKGBUILD
sed -i "1i# Maintainer: $maintainer" PKGBUILD
1 change: 1 addition & 0 deletions config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
maintainer="Your Name <your email>"
14 changes: 14 additions & 0 deletions disown.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -eo pipefail

if [[ -n "$1" ]]; then
pkgname="$1"
else
pkgname=$(exa -D | fzf --prompt "pkgname to init > " --preview="bat --color=always {}/PKGBUILD")
echo "$pkgname"
fi

git rm -r "$pkgname"
git commit -vm "disown: $pkgname" --edit
git push
24 changes: 24 additions & 0 deletions example/PKGBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Maintainer: Your Name <your email>

pkgname=example
pkgver=0.0.1
pkgrel=1
provides=('example')
conflicts=('example')
pkgdesc='example'
arch=('x86_64')
url='https://example.com'
license=('example')
depends=('example')
makedepends=('example')
optdepends=('example')
source=("https://example.com")
sha256sums=('SKIP')

build() {
echo 'build'
}

package() {
echo 'package'
}
38 changes: 38 additions & 0 deletions init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

set -eo pipefail

confirm() {
read -rp "Continue? [y/N] " reply
case "$reply" in
[yY][eE][sS] | [yY]) true ;;
*) false ;;
esac
}

if [[ "$1" == "" ]]; then
pkg=$(exa -D | fzf --prompt "pkgname to init > " --preview="bat --color=always {}/PKGBUILD")
echo "$pkg"
else
pkg="$1"
fi

git add "$pkg"

cd "$pkg"

source PKGBUILD

updpkgsums

rm -r src || true
git clean -dxn
confirm
git clean -dxf

git add -A
git diff --cached
confirm

git commit -avm "$pkg: init at $pkgver" --edit
git push
38 changes: 38 additions & 0 deletions new.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

set -eo pipefail

if [[ -n "$1" ]]; then
pkgname="$1"
else
read -rp "pkgname? " pkgname
fi

mkdir "$pkgname"

source config

echo "# Maintainer: $maintainer
pkgname=${pkgname}
pkgver=
pkgrel=1
provides=('')
conflicts=('')
pkgdesc=''
arch=('x86_64')
url=''
license=('')
depends=('')
makedepends=('')
optdepends=('')
source=(\"\")
sha256sums=('SKIP')
build() {
}
package() {
}" >"${pkgname}/PKGBUILD"
53 changes: 53 additions & 0 deletions update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

set -eo pipefail

confirm() {
read -rp "Continue? [y/N] " reply
case "$reply" in
[yY][eE][sS] | [yY]) true ;;
*) false ;;
esac
}

if [[ "$1" == "" ]]; then
pkg=$(exa -D | fzf --prompt "pkgname to update > " --preview="bat --color=always {}/PKGBUILD")
echo "$pkg"
else
pkg="$1"
fi

git add "$pkg"

cd "$pkg"

source PKGBUILD

if [[ "$2" == "" ]]; then
echo "Old version: $pkgver"
read -rp "New version? " ver
else
ver="$2"
fi

if [[ "$ver" == "$pkgver" ]]; then
rel=$(("$pkgrel" + 1))
else
rel=1
fi

sed -i "s/pkgver=.\+/pkgver=$ver/" PKGBUILD
sed -i "s/pkgrel=.\+/pkgrel=$rel/" PKGBUILD
updpkgsums

rm -r src || true
git clean -dxn
confirm
git clean -dxf

git add -A
git diff --cached
confirm

git commit -avm "$pkg: update to $ver-$rel" --edit
git push

0 comments on commit c154368

Please sign in to comment.