2023-07-16 02:01:45
This commit is contained in:
parent
b99b3993bc
commit
e1509dfce9
|
@ -0,0 +1,13 @@
|
|||
# Contributing
|
||||
|
||||
- Feedback, wishes and suggestions can be sent by email.
|
||||
- Constructive criticism, bug descriptions and other reports are welcome.
|
||||
- Email: mail@ihub.to
|
||||
|
||||
## Sources
|
||||
|
||||
- [**GitHub**](https://github.com/ghastore)
|
||||
- [GitLab](https://gitlab.com/ghastore) (MIRROR)
|
||||
- [Codeberg](https://codeberg.org/ghastore) (MIRROR)
|
||||
- [MosHub](https://hub.mos.ru/ghastore) (MIRROR)
|
||||
- [Git.Org.Ru](https://git.org.ru/ghastore) (MIRROR)
|
|
@ -0,0 +1,15 @@
|
|||
FROM debian:stable
|
||||
|
||||
LABEL "name"="Debian Package Builder"
|
||||
LABEL "description"="GitHub Action for build Debian source package."
|
||||
LABEL "maintainer"="iHub TO <mail@ihub.to>"
|
||||
LABEL "repository"="https://github.com/ghastore/build-debian.git"
|
||||
LABEL "homepage"="https://github.com/ghastore"
|
||||
|
||||
RUN apt update && apt install --yes ca-certificates
|
||||
|
||||
COPY sources-list /etc/apt/sources.list
|
||||
COPY *.sh /
|
||||
RUN apt update && apt install --yes bash curl git git-lfs rhash tar xz-utils build-essential fakeroot devscripts
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2023 GitHub Actions Store
|
||||
Copyright (c) 2023 iHub TO <https://ihub.to>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
84
README.md
84
README.md
|
@ -1 +1,83 @@
|
|||
# build-debian
|
||||
# Debian Source Package Builder
|
||||
|
||||
**GitHub Action** for build Debian **source** package.
|
||||
|
||||
## Workflow Syntax
|
||||
|
||||
```yml
|
||||
name: "Debian: Build Package"
|
||||
|
||||
on:
|
||||
- push
|
||||
|
||||
jobs:
|
||||
mirror:
|
||||
runs-on: ubuntu-latest
|
||||
name: "Build"
|
||||
steps:
|
||||
- uses: pkgstore/github-action-build-deb@main
|
||||
with:
|
||||
git_repo_src: "https://github.com/${{ github.repository }}.git"
|
||||
git_repo_dst: "https://github.com/REPO_PKG_NAME.git"
|
||||
git_user: "${{ secrets.BUILD_GIT_NAME }}"
|
||||
git_email: "${{ secrets.BUILD_GIT_EMAIL }}"
|
||||
git_token: "${{ secrets.BUILD_GIT_TOKEN }}"
|
||||
obs_user: "${{ secrets.BUILD_OBS_USER }}"
|
||||
obs_password: "${{ secrets.BUILD_OBS_PASSWORD }}"
|
||||
obs_token: "${{ secrets.BUILD_OBS_TOKEN }}"
|
||||
obs_project: "HOME:PROJECT"
|
||||
obs_package: "PKG_NAME"
|
||||
```
|
||||
|
||||
### Legend
|
||||
|
||||
- `git_repo_src` - GitHub **source repository URL**.
|
||||
- `git_repo_dst` - GitHub **destination repository URL**.
|
||||
- `git_user` - GitHub **user**.
|
||||
- `git_email` - GitHub **email**.
|
||||
- `git_token` - GitHub **token**.
|
||||
- `obs_user` - openSUSE Build Service **user**.
|
||||
- `obs_password` - openSUSE Build Service **password**.
|
||||
- `obs_token` - openSUSE Build Service **token**.
|
||||
- `obs_project` - openSUSE Build Service **project**.
|
||||
- `obs_package` - openSUSE Build Service **package**.
|
||||
|
||||
## openSUSE Build Service
|
||||
|
||||
### File: `_meta`
|
||||
|
||||
```xml
|
||||
<package name="PKG_NAME" project="HOME:PROJECT">
|
||||
<title/>
|
||||
<description/>
|
||||
</package>
|
||||
```
|
||||
|
||||
### File: `_service`
|
||||
|
||||
```xml
|
||||
<services>
|
||||
<service name="obs_scm">
|
||||
<param name="scm">git</param>
|
||||
<param name="url">https://github.com/REPO_PKG_NAME.git</param>
|
||||
<param name="revision">main</param>
|
||||
<param name="version">_none_</param>
|
||||
<param name="filename">PKG_NAME</param>
|
||||
<param name="extract">*</param>
|
||||
</service>
|
||||
<service name="tar" mode="buildtime"/>
|
||||
<service name="recompress" mode="buildtime">
|
||||
<param name="compression">xz</param>
|
||||
<param name="file">*.tar</param>
|
||||
</service>
|
||||
</services>
|
||||
```
|
||||
|
||||
### Legend
|
||||
|
||||
- `REPO_PKG_NAME` - repository with Debian source packages.
|
||||
- `PKG_NAME` - package name.
|
||||
|
||||
## Example
|
||||
|
||||
- [ext-zsh](https://github.com/pkgstore/linux-deb-ext-zsh)
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
name: "Debian Package Builder"
|
||||
author: "iHub TO <mail@ihub.to>"
|
||||
description: "GitHub Action for build Debian source package."
|
||||
branding:
|
||||
icon: "archive"
|
||||
color: "blue"
|
||||
inputs:
|
||||
git_repo_src:
|
||||
description: "Git Repository (Source)"
|
||||
required: true
|
||||
git_repo_dst:
|
||||
description: "Git Repository (Destination)"
|
||||
required: true
|
||||
git_user:
|
||||
description: "Git User"
|
||||
required: true
|
||||
git_email:
|
||||
description: "Git E-mail"
|
||||
required: true
|
||||
git_token:
|
||||
description: "Git Token"
|
||||
required: true
|
||||
obs_user:
|
||||
description: "OBS User"
|
||||
required: true
|
||||
obs_password:
|
||||
description: "OBS Password"
|
||||
required: true
|
||||
obs_token:
|
||||
description: "OBS Token"
|
||||
required: true
|
||||
obs_project:
|
||||
description: "OBS Project"
|
||||
required: true
|
||||
obs_package:
|
||||
description: "OBS Package"
|
||||
required: true
|
||||
runs:
|
||||
using: "docker"
|
||||
image: "Dockerfile"
|
||||
args:
|
||||
- ${{ inputs.git_repo_src }}
|
||||
- ${{ inputs.git_repo_dst }}
|
||||
- ${{ inputs.git_user }}
|
||||
- ${{ inputs.git_email }}
|
||||
- ${{ inputs.git_token }}
|
||||
- ${{ inputs.obs_user }}
|
||||
- ${{ inputs.obs_password }}
|
||||
- ${{ inputs.obs_token }}
|
||||
- ${{ inputs.obs_project }}
|
||||
- ${{ inputs.obs_package }}
|
|
@ -0,0 +1,292 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
# CONFIGURATION.
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
|
||||
# Vars.
|
||||
GIT_REPO_SRC="${1}"
|
||||
GIT_REPO_DST="${2}"
|
||||
GIT_USER="${3}"
|
||||
GIT_EMAIL="${4}"
|
||||
GIT_TOKEN="${5}"
|
||||
OBS_USER="${6}"
|
||||
OBS_PASSWORD="${7}"
|
||||
OBS_TOKEN="${8}"
|
||||
OBS_PROJECT="${9}"
|
||||
OBS_PACKAGE="${10}"
|
||||
PKG_NAME="$( echo "${GIT_REPO_DST}" | awk -F '[/.]' '{ print $6 }' )"
|
||||
USER_AGENT="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36"
|
||||
|
||||
# Apps.
|
||||
build="$( command -v dpkg-source )"
|
||||
cp="$( command -v cp )"
|
||||
curl="$( command -v curl )"
|
||||
date="$( command -v date )"
|
||||
git="$( command -v git )"
|
||||
hash="$( command -v rhash )"
|
||||
mkdir="$( command -v mkdir )"
|
||||
mv="$( command -v mv )"
|
||||
rm="$( command -v rm )"
|
||||
sleep="$( command -v sleep )"
|
||||
tar="$( command -v tar )"
|
||||
tee="$( command -v tee )"
|
||||
|
||||
# Dirs.
|
||||
d_src="/root/git/src"
|
||||
d_dst="/root/git/dst"
|
||||
|
||||
# Git.
|
||||
${git} config --global user.name "${GIT_USER}"
|
||||
${git} config --global user.email "${GIT_EMAIL}"
|
||||
${git} config --global init.defaultBranch 'main'
|
||||
|
||||
# Commands.
|
||||
cmd_build="${build} -i --build _build/"
|
||||
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
# INITIALIZATION.
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
|
||||
init() {
|
||||
ts_date="$( _ts_date )"
|
||||
ts_ver="$( _ts_ver )"
|
||||
|
||||
clone \
|
||||
&& ( ( pack && build && move ) 2>&1 ) | ${tee} "${d_src}/${PKG_NAME}.${ts_ver}.log" \
|
||||
&& sum \
|
||||
&& push \
|
||||
&& obs_upload \
|
||||
&& obs_trigger
|
||||
}
|
||||
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
# GIT: CLONE REPOSITORIES.
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
|
||||
clone() {
|
||||
echo "--- [GIT] CLONE: ${GIT_REPO_SRC#https://} & ${GIT_REPO_DST#https://}"
|
||||
|
||||
local src="https://${GIT_USER}:${GIT_TOKEN}@${GIT_REPO_SRC#https://}"
|
||||
local dst="https://${GIT_USER}:${GIT_TOKEN}@${GIT_REPO_DST#https://}"
|
||||
|
||||
${git} clone "${src}" "${d_src}" \
|
||||
&& ${git} clone "${dst}" "${d_dst}"
|
||||
|
||||
if [[ -d "${d_src}" ]] && [[ "$( ls -a ${d_src} )" ]]; then
|
||||
echo "--- [GIT] LIST: '${d_src}'"; ls -1 "${d_src}"
|
||||
else
|
||||
echo "ERROR: Directory ${d_src} not exist or empty!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -d "${d_dst}" ]] && [[ "$( ls -a ${d_dst} )" ]]; then
|
||||
echo "--- [GIT] LIST: '${d_dst}'"; ls -1 "${d_dst}"
|
||||
else
|
||||
echo "ERROR: Directory ${d_dst} not exist or empty!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
${sleep} 2
|
||||
}
|
||||
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
# SYSTEM: PACKING "*.ORIG" FILES.
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
|
||||
pack() {
|
||||
echo "--- [SYSTEM] PACK: '${PKG_NAME}' (*.orig.tar.xz)"
|
||||
_pushd "${d_src}" || exit 1
|
||||
|
||||
# Set package version.
|
||||
local ver="1.0.0"
|
||||
for i in "${PKG_NAME}-"*; do local ver=${i##*-}; break; done;
|
||||
|
||||
# Check '*.orig.tar.*' file.
|
||||
for i in *.orig.tar.*; do
|
||||
if [[ -f ${i} ]]; then
|
||||
echo "File '${i}' found!"
|
||||
else
|
||||
echo "File '*.orig.tar.*' not found! Creating..."
|
||||
local dir="${PKG_NAME}-${ver}"
|
||||
local tar="${PKG_NAME}_${ver}.orig.tar.xz"
|
||||
${tar} -cJf "${tar}" "${dir}"
|
||||
echo "File '${tar}' created!"
|
||||
fi
|
||||
break
|
||||
done
|
||||
|
||||
${sleep} 2; _popd || exit 1
|
||||
}
|
||||
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
# SYSTEM: BUILD PACKAGE.
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
|
||||
build() {
|
||||
echo "--- [SYSTEM] BUILD: '${GIT_REPO_SRC#https://}'"
|
||||
_pushd "${d_src}" || exit 1
|
||||
|
||||
# Run build.
|
||||
${cmd_build}
|
||||
|
||||
# Check build status.
|
||||
for i in *.dsc; do
|
||||
if [[ -f ${i} ]]; then
|
||||
echo "File '${i}' found!"
|
||||
echo "Build completed!"
|
||||
else
|
||||
echo "ERROR: File '*.dsc' not found!"
|
||||
exit 1
|
||||
fi
|
||||
break
|
||||
done
|
||||
|
||||
${sleep} 2; _popd || exit 1
|
||||
}
|
||||
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
# SYSTEM: MOVE PACKAGE TO DEBIAN PACKAGE STORE REPOSITORY.
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
|
||||
move() {
|
||||
echo "--- [SYSTEM] MOVE: '${d_src}' -> '${d_dst}'"
|
||||
|
||||
# Remove old files from 'd_dst'.
|
||||
echo "Removing old files from repository..."
|
||||
${rm} -fv "${d_dst}"/*
|
||||
|
||||
# Move new files from 'd_src' to 'd_dst'.
|
||||
echo "Moving new files to repository..."
|
||||
for i in _service _meta README.md LICENSE *.tar.* *.dsc *.log; do
|
||||
${mv} -fv "${d_src}"/${i} "${d_dst}" || exit 1
|
||||
done
|
||||
|
||||
# Copy GitHub Action 'mirror.yml' from 'd_src' to 'd_dst'.
|
||||
echo "Copy GitHub Action 'mirror.yml' to repository..."
|
||||
${mkdir} -p "${d_dst}/.github/workflows" \
|
||||
&& ${cp} "${d_src}/.github/workflows/mirror.yml" "${d_dst}/.github/workflows/"
|
||||
|
||||
${sleep} 2
|
||||
}
|
||||
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
# SYSTEM: CHECKSUM.
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
|
||||
sum() {
|
||||
echo "--- [HASH] CHECKSUM FILES"
|
||||
_pushd "${d_dst}" || exit 1
|
||||
|
||||
for i in *; do
|
||||
echo "Checksum '${i}'..."
|
||||
[[ -f "${i}" ]] && ${hash} -u "${PKG_NAME}.${ts_ver}.sha3-256" --sha3-256 "${i}"
|
||||
done
|
||||
|
||||
${sleep} 2; _popd || exit 1
|
||||
}
|
||||
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
# GIT: PUSH PACKAGE TO DEBIAN PACKAGE STORE REPOSITORY.
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
|
||||
push() {
|
||||
echo "--- [GIT] PUSH: '${d_dst}' -> '${GIT_REPO_DST#https://}'"
|
||||
_pushd "${d_dst}" || exit 1
|
||||
|
||||
# Commit build files & push.
|
||||
echo "Commit build files & push..."
|
||||
push_response=1; push_attempt=1
|
||||
|
||||
until [[ ${push_response} -eq 0 ]] || [[ ${push_attempt} -gt 5 ]]; do
|
||||
${git} add . \
|
||||
&& ${git} commit -a -m "BUILD: ${ts_date}" \
|
||||
&& ${git} push
|
||||
|
||||
push_response=$?; push_attempt=$(( push_attempt + 1 ))
|
||||
[[ ${push_response} -ne 0 ]] && ${sleep} 5
|
||||
done
|
||||
|
||||
# Exit if git push error.
|
||||
if [[ ${push_response} -ne 0 ]] && [[ ${push_attempt} -gt 5 ]]; then
|
||||
echo "ERROR: Git push error!"
|
||||
exit ${push_response}
|
||||
fi
|
||||
|
||||
${sleep} 2; _popd || exit 1
|
||||
}
|
||||
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
# CURL: UPLOAD "_META" & "_SERVICE" FILES TO OBS.
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
|
||||
obs_upload() {
|
||||
echo "--- [OBS] UPLOAD: '${OBS_PROJECT}/${OBS_PACKAGE}'"
|
||||
|
||||
if [[ -n ${OBS_PROJECT} ]] && [[ -n ${OBS_PACKAGE} ]] && [[ -n ${OBS_USER} ]] && [[ -n ${OBS_PASSWORD} ]]; then
|
||||
# Upload '_meta'.
|
||||
echo "Uploading '${OBS_PROJECT}/${OBS_PACKAGE}/_meta'..."
|
||||
${curl} -u "${OBS_USER}":"${OBS_PASSWORD}" -X PUT -T \
|
||||
"${d_dst}/_meta" "https://api.opensuse.org/source/${OBS_PROJECT}/${OBS_PACKAGE}/_meta" \
|
||||
-A "${USER_AGENT}"
|
||||
|
||||
# Upload '_service'.
|
||||
echo "Uploading '${OBS_PROJECT}/${OBS_PACKAGE}/_service'..."
|
||||
${curl} -u "${OBS_USER}":"${OBS_PASSWORD}" -X PUT -T \
|
||||
"${d_dst}/_service" "https://api.opensuse.org/source/${OBS_PROJECT}/${OBS_PACKAGE}/_service" \
|
||||
-A "${USER_AGENT}"
|
||||
else
|
||||
echo "ERROR: Insufficient data to perform the operation!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
${sleep} 5
|
||||
}
|
||||
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
# CURL: RUN BUILD PACKAGE IN OBS.
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
|
||||
obs_trigger() {
|
||||
echo "--- [OBS] TRIGGER: '${OBS_PROJECT}/${OBS_PACKAGE}'"
|
||||
if [[ -n ${OBS_PROJECT} ]] && [[ -n ${OBS_PACKAGE} ]] && [[ -n ${OBS_TOKEN} ]]; then
|
||||
${curl} -H "Authorization: Token ${OBS_TOKEN}" -X POST \
|
||||
"https://api.opensuse.org/trigger/runservice?project=${OBS_PROJECT}&package=${OBS_PACKAGE}" \
|
||||
-A "${USER_AGENT}"
|
||||
else
|
||||
echo "ERROR: Insufficient data to perform the operation!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
${sleep} 5
|
||||
}
|
||||
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
# ------------------------------------------------< COMMON FUNCTIONS >------------------------------------------------ #
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
|
||||
# Pushd.
|
||||
_pushd() {
|
||||
command pushd "$@" > /dev/null || exit 1
|
||||
}
|
||||
|
||||
# Popd.
|
||||
_popd() {
|
||||
command popd > /dev/null || exit 1
|
||||
}
|
||||
|
||||
# Timestamp: Date.
|
||||
_ts_date() {
|
||||
${date} -u '+%Y-%m-%d %T'
|
||||
}
|
||||
|
||||
# Timestamp: Version.
|
||||
_ts_ver() {
|
||||
${date} -u '+%Y-%m-%d.%H-%M-%S'
|
||||
}
|
||||
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
# -------------------------------------------------< INIT FUNCTIONS >------------------------------------------------- #
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
|
||||
init "$@"; exit 0
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
bash -c "/build.sh $*"
|
||||
|
||||
exit 0
|
|
@ -0,0 +1,3 @@
|
|||
deb https://deb.debian.org/debian stable main contrib non-free
|
||||
deb https://security.debian.org/debian-security stable-security main contrib non-free
|
||||
deb https://deb.debian.org/debian stable-updates main contrib non-free
|
Loading…
Reference in New Issue