Update workflow

This commit is contained in:
jayofelony
2024-02-25 14:23:16 +01:00
parent 73e0a1fce7
commit 3fff6182ed
5 changed files with 44 additions and 200 deletions

View File

@ -1,209 +1,53 @@
name: Publish
on:
workflow_dispatch:
inputs:
version:
description: 'Version number'
required: true
jobs:
publish:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Remove unnecessary directories
- name: Extract version from file
id: get_version
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf /usr/local/share/boost
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
VERSION=$(cut -d "'" -f2 < pwnagotchi/_version.py)
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Check disk space
run: df -BG
- name: Get latest tag
uses: actions-ecosystem/action-get-latest-tag@v1
id: get-latest-tag
- name: Checkout code
uses: actions/checkout@v4
- name: Set LAST_VERSION as an environment variable
run: echo "LAST_VERSION=${{ steps.get-latest-tag.outputs.tag }}" >> $GITHUB_ENV
- name: Validate tag
id: tag-setter
- name: Generate release notes
id: generate_release_notes
run: |
TAG=${{ github.event.inputs.version }}
if [[ $TAG =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Tag $TAG is valid."
echo "TAG=$TAG" >> $GITHUB_OUTPUT
else
echo "Tag $TAG is not a valid semantic version. Aborting."
exit 1
fi
COMMITS=$(git log --merges --pretty=format:"* %s" $LAST_VERSION..$VERSION | sed 's/$/\\n/g')
CONTRIBUTORS=$(git shortlog -sn $LAST_VERSION..$VERSION | awk '{print "* @" $2}' | sed 's/$/\\n/g')
RELEASE_BODY="## What's Changed\n$COMMITS\n\n## New Contributors\n$CONTRIBUTORS\n\n**Full Changelog**: https://github.com/jayofelony/pwnagotchi-torch/compare/$LAST_VERSION...$VERSION"
echo "RELEASE_BODY=$RELEASE_BODY" >> $GITHUB_ENV
- name: Set up Python
uses: actions/setup-python@v5
- name: Install qemu dependencies
run: sudo apt update && sudo apt install qemu-user-static qemu-utils xz-utils -y
- name: Build img file
run: ls -la .; pwd; make all
- name: Transfer .img to docker and give permissions
run: sudo chown runner:docker "pwnagotchi-rpi-bullseye-armhf.img"
- name: Compress .img file to an .img.xz
run: ls -la .; pwd; xz -z "pwnagotchi-rpi-bullseye-armhf.img"
- name: Change name of .img.xz to add version
run: mv "pwnagotchi-rpi-bullseye-armhf.img.xz" "pwnagotchi-rpi-bullseye-$VERSION-armhf.img.xz"
- name: Release
uses: softprops/action-gh-release@v1
with:
python-version: 3.9
- name: Install dependencies
run: |
sudo apt-get update && sudo apt-get install -y golang libdbus-1-dev curl unzip gettext qemu-utils qemu qemu-user-static binfmt-support
- name: Update QEMU
run: |
sudo update-binfmts --enable qemu-aarch64
sudo update-binfmts --enable qemu-arm
echo $(ls /usr/bin/qemu-arm-static)
echo $(ls /usr/bin/qemu-aarch64-static)
- name: Restart binfmt-support
run: sudo service binfmt-support restart
- name: Mount binfmt_misc
run: |
if ! grep -qs '/proc/sys/fs/binfmt_misc ' /proc/mounts; then
echo "Mounting binfmt_misc"
sudo mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
fi
- name: Restart binfmt-support
run: sudo service binfmt-support restart
- name: Update Languages
run: make update_langs
- name: Compile Languages
run: make compile_langs
- name: Check disk space
run: df -BG
- name: Check qemu-user-static package
run: |
echo "Checking qemu-user-static package..."
dpkg -s qemu-user-static && echo "qemu-user-static is installed." || echo "qemu-user-static is NOT installed."
- name: Check binfmt-support service
run: |
echo "Checking binfmt-support service..."
service binfmt-support status && echo "binfmt-support service is running." || echo "binfmt-support service is NOT running."
- name: Check binfmt_misc filesystem
run: |
echo "Checking binfmt_misc filesystem..."
mount | grep binfmt_misc && echo "binfmt_misc is mounted." || echo "binfmt_misc is NOT mounted."
echo $(ls /proc/sys/fs/binfmt_misc | grep qemu-aarch64)
- name: Run Makefile
run: make
env:
PWN_VERSION: ${{ steps.tag-setter.outputs.TAG }}
- name: PiShrink
run: |
wget https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh
chmod +x pishrink.sh
sudo mv pishrink.sh /usr/local/bin/pishrink
find /home/runner/work/ -type f -name "*.img" -exec sudo pishrink -aZ {} \;
- name: Create tag
uses: actions/github-script@v7
with:
script: |
const version = "${{ steps.tag-setter.outputs.TAG }}"
console.log(`Creating tag ${version}`)
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${version}`,
sha: context.sha
})
- name: Create Release
id: create_release
uses: actions/github-script@v7
with:
script: |
const tag = "${{ steps.tag-setter.outputs.TAG }}"
console.log(`Creating release with tag: ${tag}`)
const release = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: tag,
name: tag,
draft: false,
prerelease: false,
generate_release_notes: true
})
console.log(`Created release with id: ${release.data.id}`)
return release.data.id
- name: Upload Release Asset
id: upload-release-asset
uses: actions/github-script@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const fs = require('fs');
const path = require('path');
const release_id = "${{ steps.create_release.outputs.result }}";
const asset_content_type = 'application/octet-stream';
const distDir = '/home/runner/work/';
const uploadFile = async (filePath) => {
if (fs.lstatSync(filePath).isDirectory()) {
const files = fs.readdirSync(filePath);
for (const file of files) {
await uploadFile(path.join(filePath, file));
}
} else {
// Check if the file has a .img.xz extension
if (path.extname(filePath) === '.img.xz') {
console.log(`Uploading ${filePath}...`);
const asset_name = path.basename(filePath);
const asset_size = fs.statSync(filePath).size;
const asset = fs.createReadStream(filePath);
const response = await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release_id,
name: asset_name,
data: asset,
headers: {
'content-type': asset_content_type,
'content-length': asset_size
}
});
console.log(`Uploaded ${filePath}: ${response.data.browser_download_url}`);
}
}
}
await uploadFile(distDir);
- name: Update Release
uses: actions/github-script@v7
with:
script: |
const release_id = "${{ steps.create_release.outputs.result }}"
console.log(`Updating release with id: ${release_id}`)
github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release_id,
tag_name: "${{ steps.tag-setter.outputs.TAG }}",
name: "${{ steps.tag-setter.outputs.TAG }}",
draft: false,
prerelease: false
})
- name: Save environment variable
run: echo "${{ steps.tag-setter.outputs.TAG }}" > env_var.txt
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: env-var
path: env_var.txt
tag_name: ${{ env.VERSION }}
name: Pwnagotchi v${{ env.VERSION }}
token: ${{ secrets.TOKEN }}
files: pwnagotchi-rpi-bullseye-${{ env.VERSION }}-armhf.img.xz
body: ${{ env.RELEASE_BODY }}

View File

@ -51,12 +51,12 @@ image: clean packer
bullseye: clean packer
export=LC_ALL=en_GB.utf-8
cd builder && sudo /usr/bin/packer init data/32bit/pwnagotchi.json.pkr.hcl && sudo $(UNSHARE) /usr/bin/packer build -var "pwn_hostname=$(PWN_HOSTNAME)" -var "pwn_version=$(PWN_VERSION)" data/32bit/pwnagotchi.json.pkr.hcl
cd ~ && sudo pishrink -vaZ pwnagotchi-$(PWN_VERSION)-32bit.img
cd ~ && sudo pishrink -vaZ pwnagotchi-32bit.img
bookworm: clean packer
export=LC_ALL=en_GB.utf-8
cd builder && sudo /usr/bin/packer init data/64bit/pwnagotchi.json.pkr.hcl && sudo $(UNSHARE) /usr/bin/packer build -var "pwn_hostname=$(PWN_HOSTNAME)" -var "pwn_version=$(PWN_VERSION)" data/64bit/pwnagotchi.json.pkr.hcl
cd ~ && sudo pishrink -vaZ pwnagotchi-$(PWN_VERSION)-64bit.img
cd ~ && sudo pishrink -vaZ pwnagotchi-64bit.img
clean:
- rm -rf /tmp/packer*

View File

@ -25,7 +25,7 @@ source "arm" "rpi64-pwnagotchi" {
file_checksum_type = "sha256"
file_target_extension = "xz"
file_unarchive_cmd = ["unxz", "$ARCHIVE_PATH"]
image_path = "../../../pwnagotchi-${var.pwn_version}-64bit.img"
image_path = "../../../pwnagotchi-64bit.img"
qemu_binary_source_path = "/usr/libexec/qemu-binfmt/aarch64-binfmt-P"
qemu_binary_destination_path = "/usr/libexec/qemu-binfmt/aarch64-binfmt-P"
image_build_method = "resize"
@ -55,7 +55,7 @@ source "arm" "rpi32-pwnagotchi" {
file_checksum_type = "sha256"
file_target_extension = "xz"
file_unarchive_cmd = ["unxz", "$ARCHIVE_PATH"]
image_path = "../../pwnagotchi-${var.pwn_version}-32bit.img"
image_path = "../../pwnagotchi-32bit.img"
qemu_binary_source_path = "/usr/libexec/qemu-binfmt/arm-binfmt-P"
qemu_binary_destination_path = "/usr/libexec/qemu-binfmt/arm-binfmt-P"
image_build_method = "resize"

View File

@ -25,7 +25,7 @@ source "arm" "rpi32-pwnagotchi" {
file_checksum_type = "sha256"
file_target_extension = "xz"
file_unarchive_cmd = ["unxz", "$ARCHIVE_PATH"]
image_path = "../../pwnagotchi-${var.pwn_version}-32bit.img"
image_path = "../../pwnagotchi-32bit.img"
qemu_binary_source_path = "/usr/libexec/qemu-binfmt/arm-binfmt-P"
qemu_binary_destination_path = "/usr/libexec/qemu-binfmt/arm-binfmt-P"
image_build_method = "resize"

View File

@ -25,7 +25,7 @@ source "arm" "rpi64-pwnagotchi" {
file_checksum_type = "sha256"
file_target_extension = "xz"
file_unarchive_cmd = ["unxz", "$ARCHIVE_PATH"]
image_path = "../../../pwnagotchi-${var.pwn_version}-64bit.img"
image_path = "../../../pwnagotchi-64bit.img"
qemu_binary_source_path = "/usr/libexec/qemu-binfmt/aarch64-binfmt-P"
qemu_binary_destination_path = "/usr/libexec/qemu-binfmt/aarch64-binfmt-P"
image_build_method = "resize"