Skip to content

Commit

Permalink
Add optional repo update functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Slinet6056 committed Sep 5, 2024
1 parent 57180d5 commit 0f3d7e8
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 17 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Test build

on:
push:
branches: [master]
branches: [dev]
pull_request:
branches: [master]
branches: [dev]
workflow_dispatch:

jobs:
Expand All @@ -20,10 +20,18 @@ jobs:
package_name: ciallo
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }}
pkgs_directory: test
pkgs_path: test
repo_name: test-repo
repo_path: repo

- name: Upload Package
uses: actions/upload-artifact@main
with:
name: ciallo-package
path: test/ciallo/*.pkg.tar.zst*

- name: Upload Repository
uses: actions/upload-artifact@main
with:
name: package-repository
path: repo/
35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# archpkg-build action

This action builds ArchLinux packages in a Docker container and optionally updates a package repository.

## Example usage

```yml
Expand All @@ -8,12 +10,23 @@ with:
package_name: pkg
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }}
pkgs_directory: test # optional
pkgs_path: test # optional
repo_name: test-repo # optional
repo_path: repo # optional
```
## Inputs
- `package_name`: Name of the package to build (required)
- `gpg_private_key`: GPG private key for package signing (required)
- `gpg_passphrase`: Passphrase for the GPG private key (required)
- `pkgs_path`: Path to the directory containing package subdirectories (optional, default: ".")
- `repo_name`: Repository name (optional, for repository update)
- `repo_path`: Repository path (optional, for repository update)

## Tips

### use matrix to build multi pkgs
### Use matrix to build multiple packages

```yml
strategy:
Expand All @@ -27,3 +40,21 @@ steps:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }}
```

## How it works

1. The action uses a Docker container based on the `archlinux:base-devel` image.
2. It sets up a build environment and creates a non-root user for building packages.
3. The specified package is built using `makepkg`.
4. The built package is signed using the provided GPG key.
5. If `repo_name` and `repo_path` are provided, the action updates the package repository.

## Notes

- Ensure that your repository contains subdirectories named after each `package_name` within the `pkgs_path` (default: "."). Each subdirectory should contain the necessary `PKGBUILD` file.
- The GPG private key and passphrase should be stored as secrets in your GitHub repository.
- When updating a repository, the `repo_path` will be automatically created if it doesn't exist.

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
22 changes: 15 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
name: "Build Arch Packages"
description: "Build ArchLinux packages in Docker container"
description: "Build ArchLinux packages in Docker container and optionally update package repository"
branding:
icon: package
color: gray-dark
inputs:
package_name:
description: "Package name to build"
description: "Name of the package to build"
required: true
gpg_private_key:
description: "GPG private key for building"
description: "GPG private key for package signing"
required: true
gpg_passphrase:
description: "GPG passphrase for building"
description: "Passphrase for the GPG private key"
required: true
pkgs_directory:
description: "Directory of package subdirectories"
pkgs_path:
description: "Path to the directory containing package subdirectories (optional)"
required: false
default: "."
repo_name:
description: "Repository name (optional, for repository update)"
required: false
repo_path:
description: "Repository path (optional, for repository update)"
required: false
runs:
using: "docker"
image: "Dockerfile"
args:
- ${{ inputs.package_name }}
- ${{ inputs.gpg_private_key }}
- ${{ inputs.gpg_passphrase }}
- ${{ inputs.pkgs_directory }}
- ${{ inputs.pkgs_path }}
- ${{ inputs.repo_name }}
- ${{ inputs.repo_path }}
26 changes: 21 additions & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ set -e
pkgname=$1
gpg_private_key=$2
gpg_passphrase=$3
pkgdir=$4
pkg_path=$4
repo_name=$5
repo_path=$6

# Find the PKGBUILD directory
pkgbuild_dir=$(readlink -f "$pkgdir/$pkgname")
pkgbuild_dir=$(readlink -f "$pkg_path/$pkgname")

if [[ ! -d $pkgbuild_dir ]]; then
echo "$pkgbuild_dir should be a directory."
Expand All @@ -30,7 +32,6 @@ chown -R builder:builder "$pkgbuild_dir"

# Import GPG key
sudo -u builder bash <<EOF
export HOME=/home/builder
echo "$gpg_private_key" | gpg --batch --import
EOF

Expand All @@ -41,8 +42,23 @@ makepkg -srf --noconfirm
EOF

# Sign package
sudo -E -u builder bash <<EOF
export HOME=/home/builder
sudo -u builder bash <<EOF
cd "$pkgbuild_dir"
echo "$gpg_passphrase" | gpg --pinentry-mode loopback --passphrase-fd 0 --detach-sign *.pkg.tar.zst
EOF

# Check if repo_name and repo_path are provided
if [ -z "$repo_name" ] || [ -z "$repo_path" ]; then
echo "repo_name or repo_path not provided, skipping package repository update"
exit 0
fi

repodir=$(readlink -f "$repo_path")

# Update the package repository
sudo -u builder bash <<EOF
mkdir -p "$repodir"
cp "$pkgbuild_dir"/*.pkg.tar.zst* "$repodir"
cd "$repodir"
repo-add --verify --sign "$repo_name.db.tar.gz" *.pkg.tar.zst
EOF

0 comments on commit 0f3d7e8

Please sign in to comment.