initial commit
This commit is contained in:
commit
04e089518b
3 changed files with 225 additions and 0 deletions
9
LICENSE
Normal file
9
LICENSE
Normal file
|
@ -0,0 +1,9 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2024 actions
|
||||
|
||||
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.
|
61
README.md
Normal file
61
README.md
Normal file
|
@ -0,0 +1,61 @@
|
|||
# Arch Package Release Action
|
||||
|
||||
This action pushes Arch packages to a Forgejo Arch package repository. It could
|
||||
be run inside an `archlinux` container, like the one we provide at
|
||||
[aur/runner-image](https://git.michaelsasser.org/aur/runner-image), which comes
|
||||
with all the necessary tools, but it is not required. This action only depends
|
||||
on curl.
|
||||
|
||||
## Inputs
|
||||
|
||||
| Name | Default | Required | Description |
|
||||
| ------------------------- | --------------------------------- | -------- | ------------------------------------------------------ |
|
||||
| `package` | (Autodetect) | No | Path to the package |
|
||||
| `package_owner` | `'${{ gitea.repository_owner }}'` | No | The name of the package owner |
|
||||
| `package_repository_name` | `'extra'` | No | The name of the Arch package repository e.g. os, extra |
|
||||
| `username` | `'${{ gitea.actor }}'` | No | The username used for pushing the package |
|
||||
| `forge_url` | `'${{ gitea.server_url }}'` | No | The URL to the forge the package is pushed to. |
|
||||
| `PERSONAL_ACCESS_TOKEN` | | Yes | The PAT for used for pushing the package |
|
||||
|
||||
## Example usage
|
||||
|
||||
This example shows how this action can be used together with
|
||||
[aur/makepkg](https://git.michaelsasser.org/aur/makepkg), which builds the
|
||||
package beforehand.
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
build:
|
||||
name: Build & Lint
|
||||
runs-on: ubuntu-latest-amd64
|
||||
container:
|
||||
image: "git.michaelsasser.org/aur/runner-image:latest"
|
||||
credentials:
|
||||
username: ${{ vars.USERNAME_ACTIONS }}
|
||||
password: ${{ secrets.PERSONAL_ACCESS_TOKEN_ACTIONS }}
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: https://git.michaelsasser.org/actions/checkout@v4
|
||||
|
||||
- name: Build Package
|
||||
id: build
|
||||
uses: https://git.michaelsasser.org/actions/makepkg@main
|
||||
|
||||
- name: Build Package
|
||||
uses: https://git.michaelsasser.org/actions/arch-package-release@main
|
||||
with:
|
||||
package: ${{ steps.build.outputs.package }}
|
||||
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
|
||||
```
|
||||
|
||||
## Semantic Versioning and Branching Model
|
||||
|
||||
This action uses [SemVer](https://semver.org/) for its release cycle and
|
||||
follows the
|
||||
[GitHub Flow](https://docs.github.com/en/get-started/using-github/github-flow).
|
||||
|
||||
## License
|
||||
|
||||
Copyright © 2024 Michael Sasser <Info@MichaelSasser.org>. Released under
|
||||
the MIT license.
|
155
action.yml
Normal file
155
action.yml
Normal file
|
@ -0,0 +1,155 @@
|
|||
---
|
||||
name: arch-package-release
|
||||
description: Push Arch Package to the Forgejo Package Repository.
|
||||
author: Michael Sasser <info@michaelsasser.org>
|
||||
|
||||
branding:
|
||||
icon: shield
|
||||
color: blue
|
||||
|
||||
inputs:
|
||||
#
|
||||
# Variables
|
||||
#
|
||||
package:
|
||||
description: Path to the package.
|
||||
required: false
|
||||
default: ""
|
||||
package_owner:
|
||||
description: The name of the package owner.
|
||||
required: false
|
||||
default: ""
|
||||
package_repository_name:
|
||||
description: The name of the Arch package repository e.g. os, extra.
|
||||
required: false
|
||||
default: "extra"
|
||||
username:
|
||||
description: The username used for pushing the package.
|
||||
required: false
|
||||
default: ""
|
||||
forge_url:
|
||||
description: The URL to the forge the package is pushed to.
|
||||
required: false
|
||||
default: ""
|
||||
|
||||
#
|
||||
# Secrets
|
||||
#
|
||||
PERSONAL_ACCESS_TOKEN:
|
||||
description: The PAT for used for pushing the package.
|
||||
required: true
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Prepare
|
||||
id: prepared
|
||||
shell: bash
|
||||
run: |
|
||||
echo '::group::Prepared Data'
|
||||
|
||||
#
|
||||
# Forge URL
|
||||
#
|
||||
echo "gitea.server_url = ${{ gitea.server_url }}"
|
||||
echo "inputs.forge_url = ${{ inputs.forge_url }}"
|
||||
FORGE_URL='${{ gitea.server_url }}'
|
||||
if [ -n '${{ inputs.forge_url }}' ]; then
|
||||
FORGE_URL='${{ inputs.forge_url }}'
|
||||
fi
|
||||
echo "Setting forge URL to ${FORGE_URL}"
|
||||
echo "::set-output name=forge_url::${FORGE_URL}"
|
||||
|
||||
#
|
||||
# Package
|
||||
#
|
||||
files=(*.pkg.tar.zst)
|
||||
echo "Files discovered: ${files}"
|
||||
echo "inputs.package = ${{ inputs.package }}"
|
||||
if [ -n '${{ inputs.package }}' ]; then
|
||||
if [[ "${#files[@]}" == 1 ]]; then
|
||||
|
||||
echo "Setting package to ${files[0]}"
|
||||
echo "::set-output name=package::${files[0]}"
|
||||
else
|
||||
echo "::error title=package::No package was provided and the number of packages in the output is greater than 1."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
#
|
||||
# Package Owner
|
||||
#
|
||||
echo "gitea.repository_owner = ${{ gitea.repository_owner }}"
|
||||
echo "inputs.package_owner = ${{ inputs.package_owner }}"
|
||||
PACKAGE_OWNER='${{ gitea.repository_owner }}'
|
||||
if [ -n '${{ inputs.package_owner }}' ]; then
|
||||
PACKAGE_OWNER='${{ inputs.package_owner }}'
|
||||
fi
|
||||
echo "Setting forge URL to ${PACKAGE_OWNER}"
|
||||
echo "::set-output name=package_owner::${PACKAGE_OWNER}"
|
||||
|
||||
#
|
||||
# Username
|
||||
#
|
||||
echo "gitea.actor = ${{ gitea.actor }}"
|
||||
echo "inputs.username = ${{ inputs.username }}"
|
||||
USERNAME='${{ gitea.actor }}'
|
||||
if [ -n '${{ inputs.username }}' ]; then
|
||||
USERNAME='${{ inputs.username }}'
|
||||
fi
|
||||
echo "Setting username to ${USERNAME}"
|
||||
echo "::set-output name=username::${USERNAME}"
|
||||
|
||||
echo '::endgroup::'
|
||||
|
||||
# TODO: Handle overwrite
|
||||
- name: Push Package
|
||||
shell: bash
|
||||
run: |
|
||||
echo '::group::cURL Version'
|
||||
curl --version
|
||||
echo '::endgroup::'
|
||||
|
||||
PACKAGE_URL='${{ steps.prepared.outputs.forge_url }}/api/packages/${{ steps.prepared.outputs.repository_owner }}/arch/${{ inputs.package_repository_name }}'
|
||||
|
||||
echo '::group::Request'
|
||||
RESPONSE=$(
|
||||
curl -X PUT "${PACKAGE_URL}" \
|
||||
--silent \
|
||||
--verbose \
|
||||
--write-out '\n%{http_code}' \
|
||||
--user '${{ steps.prepared.outputs.username }}:${{ inputs.PERSONAL_ACCESS_TOKEN }}' \
|
||||
--header 'Content-Type: application/octet-stream' \
|
||||
--data-binary "@${{ steps.prepared.outputs.package }}"
|
||||
)
|
||||
echo '::endgroup::'
|
||||
|
||||
HTTP_CODE=$(tail -n1 <<<"${RESPONSE}")
|
||||
CONTEXT=$(sed '$ d' <<<"${RESPONSE}")
|
||||
|
||||
echo '::group::Response'
|
||||
echo "${CONTEXT}"
|
||||
echo '::endgroup::'
|
||||
|
||||
echo '::group::HTTP Code'
|
||||
echo "${HTTP_CODE}"
|
||||
echo '::endgroup::'
|
||||
|
||||
if (($HTTP_CODE >= 200 && $HTTP_CODE <= 399)); then
|
||||
# Success
|
||||
echo 'The package \'${{ steps.prepared.outputs.package }}\' was successfully pushed to the package registry'
|
||||
exit 0
|
||||
elif (($HTTP_CODE >= 400 && $HTTP_CODE <= 499)); then
|
||||
# Client Error
|
||||
if [[ "$HTTP_CODE" == 409 ]]; then
|
||||
echo "::warning title=package already exists::The package with the same name, pkgver, pkgrel and architecture ('${{ steps.prepared.outputs.package }}') already exists and was therefore not updated."
|
||||
exit 0
|
||||
if
|
||||
echo "::error title=Client Error::The server returned a client error with the HTTP code '${HTTP_CODE}'."
|
||||
exit 1
|
||||
elif (($HTTP_CODE >= 500 && $HTTP_CODE <= 599)); then
|
||||
# Server error
|
||||
echo "::error title=Server Error::The server returned a server error with the HTTP code '${HTTP_CODE}'."
|
||||
exit 1
|
||||
fi
|
Loading…
Add table
Reference in a new issue