Build image #530
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
name: Build image | |
on: | |
push: | |
branches: | |
- master | |
schedule: | |
# * is a special character in YAML so you have to quote this string | |
- cron: "14 3 */16 * *" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install required packages | |
run: | | |
export TERM=linux | |
sudo apt-get update | |
sudo apt-get install kpartx binfmt-support qemu-user-static qemu-utils libguestfs-tools ansible | |
- name: Set env | |
run: | | |
PACKER_VERSION="1.10.2" | |
echo "PACKER_VERSION=${PACKER_VERSION}" >> $GITHUB_ENV | |
ARM_IMG="/tmp/arm64.img" | |
echo "ARM_IMG=${ARM_IMG}" >> $GITHUB_ENV | |
ARCH="arm64" | |
FLAVOR="generic" | |
RELEASE="bookworm" | |
REL_VERSION="12" | |
REL_DATE="latest" | |
DEB_IMG="https://cdimage.debian.org/images/cloud/${RELEASE}/daily/${REL_DATE}/debian-${REL_VERSION}-${FLAVOR}-${ARCH}-daily.qcow2" | |
#UBU_IMG="https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-arm64.img" | |
echo "B_IMG=${DEB_IMG}" >> $GITHUB_ENV | |
curl https://www.home-assistant.io/version.json -o /tmp/version.js | |
VERSION=$(jq -r .current_version /tmp/version.js) | |
echo "VERSION=${VERSION}" >> $GITHUB_ENV | |
REL_NOTES=$(jq -r '."release_notes"' /tmp/version.js) | |
echo "REL_NOTES=${REL_NOTES}" >> $GITHUB_ENV | |
S_URL_VERSION="https://version.home-assistant.io/stable.json" | |
S_VERSION=$(curl -s ${S_URL_VERSION} | jq -e -r '.supervisor') | |
echo "S_VERSION=${S_VERSION}" >> $GITHUB_ENV | |
- name: Packer ${{ env.PACKER_VERSION }} setup | |
run: | | |
PACKER_VERSION=${{ env.PACKER_VERSION }} | |
curl https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip -o /tmp/packer.zip | |
unzip /tmp/packer.zip -d /tmp | |
sudo mv /tmp/packer /usr/bin/packer | |
git clone https://github.com/foreign-sub/packer-builder-arm-image.git /tmp/packer-builder-arm-image | |
cd /tmp/packer-builder-arm-image && git checkout testing | |
cd /tmp/packer-builder-arm-image && go mod download && go build | |
sudo cp /tmp/packer-builder-arm-image/packer-builder-arm-image /usr/bin | |
- name: Download image | |
run: | | |
curl -L ${{ env.B_IMG }} -o /tmp/arm64.qcow2 | |
qemu-img convert /tmp/arm64.qcow2 ${{ env.ARM_IMG }} | |
- name: Build image for ${{ env.VERSION }} | |
run: | | |
INIT_PATH=$(pwd) | |
mkdir -p /tmp/mnt | |
cd tasks && sudo /usr/bin/packer build -var "is_url=${{ env.ARM_IMG }}" -var "version=${{ env.VERSION }}" -var "init_path=${INIT_PATH}" ha_fbx_arm64.json | |
sudo mv output-hafbx/image ${INIT_PATH} | |
rm ${{ env.ARM_IMG }} | |
- name: Resize and pack image for ${{ env.VERSION }} | |
run: | | |
sudo virt-filesystems --long -h --all -a image | |
mv image /tmp/image | |
sudo virt-sparsify /tmp/image --convert qcow2 hafbx-debian-${{ env.VERSION }}.qcow2 | |
sudo qemu-img resize hafbx-debian-${{ env.VERSION }}.qcow2 +14G | |
sudo qemu-img info hafbx-debian-${{ env.VERSION }}.qcow2 > hafbx-debian-${{ env.VERSION }}.imginfo | |
echo "IMG_INFO=$(cat hafbx-debian-${{ env.VERSION }}.imginfo | tr '\n' ' ')" >> $GITHUB_ENV | |
sudo virt-filesystems --long -h --all -a hafbx-debian-${{ env.VERSION }}.qcow2 | |
sudo sha256sum hafbx-debian-${{ env.VERSION }}.qcow2 > hafbx-debian-${{ env.VERSION }}.sha256 | |
echo "SHA=$(cat hafbx-debian-${{ env.VERSION }}.sha256)" >> $GITHUB_ENV | |
sudo zip hafbx-debian-${{ env.VERSION }}.zip hafbx-debian-${{ env.VERSION }}.sha256 hafbx-debian-${{ env.VERSION }}.qcow2 | |
- name: Clean | |
run: | | |
echo "Build done" | |
pwd | |
ls -lastr | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@latest | |
env: | |
GITHUB_TOKEN: ${{ secrets.UPLOAD_TOKEN }} | |
with: | |
tag_name: ${{ env.VERSION }} | |
release_name: Debian HA ${{ env.VERSION }} VM image for arm64 | |
body: | | |
Home Assistant ${{ env.VERSION }} | |
= | |
Release notes : ${{ env.REL_NOTES }} | |
- | |
Supervisor : ${{ env.S_VERSION }} | |
Debian source image : ${{ env.B_IMG }} | |
sha256 : ${{ env.SHA }} | |
Image info: ${{ env.IMG_INFO }} | |
draft: false | |
prerelease: false | |
- name: Upload Release Asset | |
id: upload-release-asset | |
uses: actions/[email protected] | |
env: | |
GITHUB_TOKEN: ${{ secrets.UPLOAD_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./hafbx-debian-${{ env.VERSION }}.zip | |
asset_name: hafbx-debian-${{ env.VERSION }}.zip | |
asset_content_type: application/zip |