Skip to content

Build QR

Build QR #14

Workflow file for this run

#
# Copyright (C) 2022 Ing <https://github.com/wjz304>
#
# This is free software, licensed under the MIT License.
# See /LICENSE for more information.
#
name: Build QR
on:
workflow_dispatch:
inputs:
version:
description: "format %y.%-m.$i or auto"
required: false
type: string
prerelease:
description: "pre release"
default: false
type: boolean
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@main
#with:
# lfs: 'true'
- name: Checkout
uses: actions/checkout@main
with:
repository: RROrg/qr
token: ${{ secrets.RRORG }}
path: qr
# Install dependencies
- name: Install dependencies
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
sudo apt update
sudo apt install -y jq cpio gettext
sudo snap install yq
# calculates the version number and push
- name: Calculate version
run: |
# Calculate version
VERSION=""
if [ -n "${{ inputs.version }}" ]; then
if [ "$(echo ${{ inputs.version }} | cut -d '.' -f 1,2)" = "$(date +'%y.%-m')" ]; then
VERSION="${{ inputs.version }}"
else
LATEST_TAG="$(curl -skLH "Authorization: token ${{ secrets.RRORG }}" "https://api.github.com/repos/RROrg/qr/releases" | jq -r ".[0].tag_name" 2>/dev/null)"
if [ -n "${LATEST_TAG}" -a "$(echo ${LATEST_TAG} | cut -d '.' -f 1,2)" = "$(date +'%y.%-m')" ]; then # format %y.%-m.$i
VERSION="$(echo ${LATEST_TAG} | awk -F '.' '{$3=$3+1}1' OFS='.')"
else
VERSION="$(date +'%y.%-m').0"
fi
fi
else
VERSION=""
fi
echo "VERSION: ${VERSION}"
echo "VERSION=${VERSION}" >>$GITHUB_ENV
if [ -n "${VERSION}" ]; then
cd qr
# Modify Source File
echo "${VERSION}" >VERSION
echo "${VERSION}" > files/mnt/p1/QR_VERSION
sed 's/^QR_VERSION=.*/QR_VERSION="'${VERSION}'"/' -i files/initrd/opt/qr/include/consts.sh
git checkout main
git pull
status=$(git status -s | awk '{printf " %s", $2}')
if [ -n "${status}" ]; then
git add ${status}
git commit -m "update $(date +%Y-%m-%d" "%H:%M:%S)"
git push -f
fi
fi
# Convert po2mo, addons and Modules
- name: Convert po2mo, addons and Modules
run: |
PRE="${{ inputs.prerelease }}"
cd qr
. scripts/func.sh "${{ secrets.RRORG }}"
echo "Get extractor"
getAddons "files/mnt/p8/addons" "${PRE}"
getModules "files/mnt/p8/modules" "${PRE}"
getBuildroot "files/mnt/p8" "${PRE}"
echo "Repack initrd"
convertpo2mo "files/initrd/opt/qr/lang"
repackInitrd "files/mnt/p8/initrd-qr" "files/initrd"
echo "OK"
# Build incremental
- name: Build image
run: |
cd qr
. scripts/func.sh "${{ secrets.RRORG }}"
echo "Create RR image"
gzip -dc "files/initrd/opt/qr/grub.img.gz" >"qr.img"
fdisk -l "qr.img"
LOOPX=$(sudo losetup -f)
sudo losetup -P "${LOOPX}" "qr.img"
echo "Mounting image file"
mkdir -p "/tmp/p1"
mkdir -p "/tmp/p8"
sudo mount ${LOOPX}p1 "/tmp/p1"
sudo mount ${LOOPX}p8 "/tmp/p8"
echo "Copying files"
sudo cp -Rf "files/mnt/p1/"* "/tmp/p1"
sudo cp -Rf "files/mnt/p8/"* "/tmp/p8"
sync
echo "Unmount image file"
sudo umount "/tmp/p1"
sudo umount "/tmp/p8"
rmdir "/tmp/p1"
rmdir "/tmp/p8"
sudo losetup --detach ${LOOPX}
# echo "Image Converter"
# qemu-img convert -O vmdk qr.img qr-dyn.vmdk
# qemu-img convert -O vmdk -o adapter_type=lsilogic qr.img -o subformat=monolithicFlat qr.vmdk
# Zip image and generate checksum
- name: Pack
run: |
cd qr
VERSION="${{ env.VERSION }}"
VERSION="${VERSION:-"test"}"
zip -9 "qr-${VERSION}.img.zip" qr.img
# zip -9 "qr-${VERSION}.vmdk-dyn.zip" qr-dyn.vmdk
# zip -9 "qr-${VERSION}.vmdk-flat.zip" qr.vmdk qr-flat.vmdk
# update.zip
sha256sum update-list.yml update-check.sh >sha256sum
zip -9j "update-${VERSION}.zip" update-list.yml update-check.sh
while read F; do
if [ -d "${F}" ]; then
FTGZ="$(basename "${F}").tgz"
tar -zcf "${FTGZ}" -C "${F}" .
sha256sum "${FTGZ}" >>sha256sum
zip -9j "update-${VERSION}.zip" "${FTGZ}"
rm -f "${FTGZ}"
else
(cd $(dirname "${F}") && sha256sum $(basename "${F}")) >>sha256sum
zip -9j "update-${VERSION}.zip" "${F}"
fi
done < <(yq '.replace | explode(.) | to_entries | map([.key])[] | .[]' update-list.yml)
zip -9j "update-${VERSION}.zip" sha256sum
# updateall.zip
rm -f sha256sum
echo ' "files/mnt/p8/addons/": "/mnt/p8/addons/"' >> update-list.yml
echo ' "files/mnt/p8/modules/": "/mnt/p8/modules/"' >> update-list.yml
zip -9j "updateall-${VERSION}.zip" update-list.yml update-check.sh
while read F; do
if [ -d "${F}" ]; then
FTGZ="$(basename "${F}").tgz"
tar -zcf "${FTGZ}" -C "${F}" .
sha256sum "${FTGZ}" >>sha256sum
zip -9j "updateall-${VERSION}.zip" "${FTGZ}"
rm -f "${FTGZ}"
else
(cd $(dirname "${F}") && sha256sum $(basename "${F}")) >>sha256sum
zip -9j "updateall-${VERSION}.zip" "${F}"
fi
done < <(yq '.replace | explode(.) | to_entries | map([.key])[] | .[]' update-list.yml)
zip -9j "updateall-${VERSION}.zip" sha256sum
# Upload artifact
- name: Upload to Artifacts
if: success() && env.VERSION == ''
uses: actions/upload-artifact@v4
with:
name: Images
path: |
qr/qr*.zip
qr/update*.zip
retention-days: 5
# Publish a release if is a tag
- name: Release
if: success() && env.VERSION != ''
uses: ncipollo/release-action@v1
with:
tag: ${{ env.VERSION }}
prerelease: ${{ inputs.prerelease }}
artifacts: |
qr/qr*.zip
qr/update*.zip
body: |
- Editing ...
owner: RROrg
repo: qr
token: ${{ secrets.RRORG }}