Build QR #34
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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 timedatectl set-timezone "Asia/Shanghai" | |
sudo apt update | |
sudo apt install -y locales busybox dialog gettext sed gawk jq curl | |
sudo apt install -y python-is-python3 python3-pip libelf-dev qemu-utils cpio xz-utils lz4 lzma bzip2 gzip zstd | |
# sudo snap install yq | |
if ! command -v yq &>/dev/null || ! yq --version 2>/dev/null | grep -q "v4."; then | |
sudo curl -kL https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -o /usr/bin/yq && sudo chmod a+x /usr/bin/yq | |
fi | |
# calculates the version number and push | |
- name: Calculate version | |
run: | | |
# Calculate version | |
TAGDATE="$(date +'%Y%m%d%H%M')" | |
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}" ] && [ "$(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 "TAGDATE: ${TAGDATE}" | |
echo "VERSION: ${VERSION}" | |
echo "TAGDATE=${TAGDATE}" >>$GITHUB_ENV | |
echo "VERSION=${VERSION}" >>$GITHUB_ENV | |
cd qr | |
if [ -n "${VERSION}" ]; then | |
# Modify Source File | |
echo "${VERSION}" >VERSION | |
echo "${VERSION}" > files/mnt/p1/QR_VERSION | |
sed -i "s/^QR_VERSION=.*/QR_VERSION=\"${VERSION}\"/" 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 | |
else | |
sed -i "s/^QR_VERSION=.*/QR_VERSION=\"${TAGDATE}\"/" files/initrd/opt/qr/include/consts.sh | |
fi | |
cd - | |
# Convert po2mo, Get exts | |
- name: Convert po2mo, addons and Modules | |
run: | | |
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" | |
[ "${{ inputs.prerelease }}" = "true" ] && RELEASE="pre" || RELEASE="" | |
sed -i "s/^QR_RELEASE=.*$/RR_RELEASE=\"${RELEASE}\"/" files/initrd/opt/qr/include/consts.sh | |
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" | |
for i in 1 2 3 5 8; do | |
[ ! -d "files/mnt/p${i}" ] && continue | |
rm -rf "/tmp/mnt/p${i}" | |
mkdir -p "/tmp/mnt/p${i}" | |
echo "Mounting ${LOOPX}p${i}" | |
sudo mount "${LOOPX}p${i}" "/tmp/mnt/p${i}" || { | |
echo "Can't mount ${LOOPX}p${i}." | |
break | |
} | |
echo "Copying files to ${LOOPX}p${i}" | |
[ ${i} -eq 1 ] && sudo cp -af "files/mnt/p${i}/"{.locale,.timezone} "/tmp/mnt/p${i}/" 2>/dev/null || true | |
sudo cp -rf "files/mnt/p${i}/"* "/tmp/mnt/p${i}" || true | |
sudo sync | |
echo "Unmounting ${LOOPX}p${i}" | |
sudo umount "/tmp/mnt/p${i}" || { | |
echo "Can't umount ${LOOPX}p${i}." | |
break | |
} | |
rm -rf "/tmp/mnt/p${i}" | |
done | |
sudo losetup --detach "${LOOPX}" | |
# Zip image and generate checksum | |
- name: Pack | |
run: | | |
cd qr | |
TAGDATE="${{ env.TAGDATE }}" | |
VERSION="${{ env.VERSION }}" | |
VERSION="${VERSION:-"${TAGDATE}"}" | |
sha256sum qr.img >sha256sum | |
zip -9 "qr-${VERSION}.img.zip" qr.img sha256sum | |
# 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 | |
# sha256sum | |
sha256sum "qr-${VERSION}.img.zip" >sha256sum | |
sha256sum "update-${VERSION}.zip" >>sha256sum | |
sha256sum "updateall-${VERSION}.zip" >>sha256sum | |
# Upload artifact | |
- name: Upload to Artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: qr.img | |
path: | | |
qr/qr-*.img.zip | |
retention-days: 5 | |
- name: Upload to Artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: update | |
path: | | |
qr/update-*.zip | |
retention-days: 5 | |
- name: Upload to Artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: updateall | |
path: | | |
qr/updateall-*.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 | |
qr/sha256sum | |
body: | | |
- Please do not upgrade this version now (In release testing...), | |
- Please upgrade after updating the Changelog ... | |
owner: RROrg | |
repo: qr | |
token: ${{ secrets.RRORG }} |