Skip to content

Commit

Permalink
Add pack-debian to main
Browse files Browse the repository at this point in the history
  • Loading branch information
igorpecovnik committed Oct 13, 2024
1 parent d1a8720 commit 691af7a
Showing 1 changed file with 258 additions and 0 deletions.
258 changes: 258 additions & 0 deletions .github/workflows/pack-debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
name: Build, release, upload to GH & server

on:
workflow_dispatch:
workflow_call:
inputs:
matrix:
required: true
type: string
maintainer:
required: true
type: string
package:
required: true
type: string
licence:
required: false
type: string
homepage:
required: false
type: string
depends:
required: false
type: string
section:
required: false
type: string
priority:
required: false
type: string
description:
required: false
type: string

secrets:
GPG_PRIVATE_KEY:
required: true
PASSPHRASE:
required: true
SSH_KEY_TORRENTS:
required: false
KNOWN_HOSTS_UPLOAD:
required: false

jobs:

prepare:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.prep.outputs.JSON_CONTENT }}
steps:
- name: Prepare releases
id: prep
run: |
echo 'JSON_CONTENT<<EOF' >> $GITHUB_OUTPUT
printf "{ \"matrix\":\"${{ inputs.matrix }}\", \"created\":\"$(date -u +'%Y%m%d-%H%M')\"}\n" | jq -s >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
build:
needs: [ prepare ]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node: ${{fromJson(needs.prepare.outputs.matrix)}}

steps:

- name: "Checkout Armbian OS"
uses: actions/checkout@v4
with:
repository: armbian/os
ref: main
fetch-depth: 1
path: os

- name: "Checkout this repository"
uses: actions/checkout@v4
with:
path: source

- name: Build ${{ matrix.node }}
run: |
ARCH=$(echo ${{ matrix.node }} | cut -d":" -f1)
PKG_NAME=${{ inputs.package }}_${{needs.prepare.outputs.created}}_${ARCH}
mkdir -p output/${PKG_NAME}/DEBIAN
cat <<-END > output/${PKG_NAME}/DEBIAN/control
Package: ${{ inputs.package }}
Version: ${{needs.prepare.outputs.created}}
Architecture: ${ARCH}
END
if [[ -n "${{ inputs.maintainer }}" ]]; then
echo "Maintainer: ${{ inputs.maintainer }}" >> output/${PKG_NAME}/DEBIAN/control
fi
if [[ -n "${{ inputs.depends }}" ]]; then
echo "Depends: ${{ inputs.depends }}" >> output/${PKG_NAME}/DEBIAN/control
fi
if [[ -n "${{ inputs.section }}" ]]; then
echo "Section: ${{ inputs.section }}" >> output/${PKG_NAME}/DEBIAN/control
fi
if [[ -n "${{ inputs.priority }}" ]]; then
echo "Priority: ${{ inputs.priority }}" >> output/${PKG_NAME}/DEBIAN/control
fi
if [[ -n "${{ inputs.description }}" ]]; then
echo "Description: ${{ inputs.description }}" >> output/${PKG_NAME}/DEBIAN/control
fi
if [[ -f source/debian.conf ]]; then
while read p; do
FILE=$(echo $p | cut -d":" -f1)
LOCATION=$(echo $p | cut -d":" -f2 | cut -d"/" -f2-)
if [[ -n $LOCATION && -n $FILE ]]; then
mkdir -p "output/${PKG_NAME}/$LOCATION"
cp -R source/$FILE "output/${PKG_NAME}/$LOCATION"
fi
done < source/debian.conf
fi
fakeroot dpkg-deb -b output/${PKG_NAME}/
cd output/${PKG_NAME}/
tar cvfz ../${PKG_NAME}.tar.gz .
- name: Upload deb as artifact ${{ matrix.node }}
uses: actions/upload-artifact@v3
with:
name: deb
path: output/*.deb

- name: Upload tarball as artifact ${{ matrix.node }}
uses: actions/upload-artifact@v3
with:
name: tar
path: output/*.tar.gz

release:
needs: [ prepare, build ]
if: "${{ always() }}"
runs-on: ubuntu-latest
steps:

- name: Install dependencies
run: |
echo 'man-db man-db/auto-update boolean false' | sudo debconf-set-selections
sudo apt-get -q -y install reprepro
- uses: actions/[email protected]
name: Download deb artifacts
with:
name: deb
path: output

- uses: actions/[email protected]
name: Download tarball artifacts
with:
name: tar
path: output

- name: Checkout
uses: actions/[email protected]
with:
path: repository
ref: repository

- name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v5
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}

- name: Configure git identity
working-directory: repository
run: |
echo "Testing signing" | gpg --sign --armor
gpg -K
echo "#"
git config user.name github-actions
git config user.email [email protected]
- name: Deploy packages
run: |
PACKAGES_DIR="$(pwd)"/output
REPO_DIR="$(pwd)"/repository
[[ ! -d "${PACKAGES_DIR}" ]] && echo "Packages dir ${PACKAGES_DIR} is not there." && exit 2
mkdir -p "${REPO_DIR}" "${REPO_DIR}"/pool
# Configure reprepro
mkdir -p ${REPO_DIR}/conf
cat <<EOD >${REPO_DIR}/conf/distributions
Origin: armbian.github.io/configurator
Label: armbian.github.io/configurator
Codename: stable
Architectures: amd64 arm64 armhf
Components: main
Description: Armbian development repo
SignWith: DF00FAF1C577104B50BF1D0093D6889F9F0E78D5
EOD
# Determine a list of binary debs to include in the repo
# reprepro does not accept identical package(-names) with different contents (sha1)
# our build does generate different contents (in different runs) and I'd like to keep old versions around
LIST_DEBS_NEW=""
for ONE_DEB in ${PACKAGES_DIR}/*.deb; do
echo "Considering adding to repo: $ONE_DEB"
BASE_ONE_DEB=$(basename ${ONE_DEB})
EXISTING_DEB_IN_REPO=$(find ${REPO_DIR}/pool -type f -name ${BASE_ONE_DEB})
if [[ "a${EXISTING_DEB_IN_REPO}" == "a" ]]; then
echo "- New .deb to include in repo: ${BASE_ONE_DEB}"
LIST_DEBS_NEW="${LIST_DEBS_NEW} ${ONE_DEB}"
else
echo "- Existing .deb: ${BASE_ONE_DEB}"
fi
done
echo "** Final list of DEBs to include: ${LIST_DEBS_NEW}"
if [[ "a${LIST_DEBS_NEW}a" == "aa" ]]; then
echo "No new packages, nothing to do."
else
echo "New packages, running reprepro..."
reprepro -b "${REPO_DIR}" includedeb stable ${LIST_DEBS_NEW}
echo "Repository generated at ${REPO_DIR}/"
fi
cd ${REPO_DIR}
git add .
git commit -m "Updating repo" || true
git push origin repository || true
# - name: Install SSH key for storage
# uses: shimataro/ssh-key-action@v2
# with:
# key: ${{ secrets.SSH_KEY_TORRENTS }}
# known_hosts: ${{ secrets.KNOWN_HOSTS_UPLOAD }}
# if_key_exists: replace

# - name: Deploy to server
# run: |
# ls -l build/output/images/*/*/
# sudo apt-get -y -qq install lftp
# lftp -u upload, -e "set net:timeout 4;set net:max-retries 6;mirror --Remove-source-files -R --no-empty-dirs --parallel=8 --no-perms $(pwd)/build/output/images/ images/ ;bye" sftp://users.armbian.com

- name: "GH specific release"
uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "${{needs.prepare.outputs.created}}"
prerelease: false
title: "${{needs.prepare.outputs.created}}"
files: |
output/*.deb
output/*.tar.gz

0 comments on commit 691af7a

Please sign in to comment.