💚 Su instead of sudo #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release-plz | |
permissions: | |
pull-requests: write | |
contents: write | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
release-plz: | |
name: Release-plz | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Install Rust toolchain | |
uses: dtolnay/rust-toolchain@stable | |
- name: Run release-plz | |
uses: MarcoIeni/release-plz-action@v0.5 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
publish-aur: | |
needs: release-plz | |
runs-on: ubuntu-latest | |
container: | |
image: archlinux:base-devel | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install git and gnupg | |
run: pacman -Syu --noconfirm git gnupg openssh | |
- name: Create non-root user | |
run: | | |
useradd -m builder | |
echo "builder ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers | |
- name: Update PKGBUILD | |
run: | | |
version=$(grep '^version =' Cargo.toml | sed 's/.*= "\(.*\)"/\1/') | |
sed "s/pkgver=.*/pkgver=$version/" PKGBUILD.template > PKGBUILD | |
sum=$(curl -sL "https://crates.io/api/v1/crates/image-colorizer/$version/download" | sha256sum | cut -d ' ' -f 1) | |
sed -i "s/sha256sums=('PLACEHOLDER')/sha256sums=('$sum')/" PKGBUILD | |
- name: Generate .SRCINFO | |
run: | | |
chown -R builder:builder . | |
sudo -u builder makepkg --printsrcinfo > .SRCINFO | |
- name: Import GPG key | |
env: | |
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} | |
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} | |
run: | | |
sudo -u builder bash << EOF | |
echo "$GPG_PRIVATE_KEY" | gpg --batch --import | |
echo "allow-loopback-pinentry" >> ~/.gnupg/gpg-agent.conf | |
echo "pinentry-mode loopback" >> ~/.gnupg/gpg.conf | |
gpg-connect-agent reloadagent /bye | |
EOF | |
- name: Publish to AUR | |
env: | |
AUR_SSH_PRIVATE_KEY: ${{ secrets.AUR_SSH_PRIVATE_KEY }} | |
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} | |
run: | | |
su builder | |
mkdir -p ~/.ssh | |
echo "$AUR_SSH_PRIVATE_KEY" > ~/.ssh/aur | |
chmod 600 ~/.ssh/aur | |
eval $(ssh-agent -s) | |
ssh-add ~/.ssh/aur | |
ssh-keyscan aur.archlinux.org >> ~/.ssh/known_hosts | |
git config --global user.name "Taylor Beeston" | |
git config --global user.email "beeston.taylor@gmail.com" | |
git config --global user.signingkey $(gpg --list-secret-keys --keyid-format LONG | grep sec | awk '{print $2}' | cut -d'/' -f2) | |
git config --global commit.gpgsign true | |
git clone ssh://aur@aur.archlinux.org/image-colorizer.git aur-repo | |
cp PKGBUILD .SRCINFO aur-repo/ | |
cd aur-repo | |
git add PKGBUILD .SRCINFO | |
echo $GPG_PASSPHRASE | git commit -S -m "Update to version $(grep -oP '(?<=pkgver=)\S+' PKGBUILD)" | |
git push | |
exit |