Skip to content

Enhanced x735-Script: Packaging, Performance, and Automation #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 139 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
af56f50
initiate the package essential files
Jul 25, 2023
62b50b4
create control file for the Debian package
Jul 25, 2023
2063d68
create the rules file and define the build process
Jul 25, 2023
b583983
specify the debhelper compatibility level
Jul 25, 2023
b2781f8
restructure the script files as a debian package
Jul 25, 2023
e2249fc
get rid of python files
Jul 25, 2023
7330a84
create postinst script to enable pwm on pkg install
Jul 27, 2023
31af6db
improving comments and logs
Jul 27, 2023
97cf773
create backup before edite and add file check
Jul 27, 2023
88537f2
exit script when a command produces a non-success exit status
Jul 27, 2023
e4ff2c8
add guard clause to check if sudo running the script
Jul 27, 2023
a24ceac
typo: fix hardcoded text
Jul 27, 2023
95c8d80
refactor the soft shutdown method
Jul 27, 2023
649938e
improve the x735off script for more readability
Jul 27, 2023
8ac538e
add cleanup mechanism to x735off command
Jul 27, 2023
4883c36
display the shutdown message to all users.
Jul 27, 2023
422a694
add sudo guard clause
Jul 27, 2023
698a4c6
Standerize error codes
Jul 27, 2023
721dc4a
Ensure that all variables that are not meant to be modified
Jul 27, 2023
f452988
Use printf instead of echo for consistent output
Jul 27, 2023
fce37e3
handle SIGINT (Ctrl+C) and SIGTERM signals
Jul 27, 2023
9953917
refactor the pwr control btn functionality
Jul 28, 2023
a7bd2f9
FIX Consistent naming conventions
Jul 28, 2023
7017fdf
activate the poweroff and reboot commands
Jul 28, 2023
eac272c
relocate the services
Jul 28, 2023
e05b191
replace the services files to follow the convetionals
Jul 28, 2023
15bcb72
enabling and starting the services after install
Jul 28, 2023
82a25aa
including the package files in the control file
Jul 28, 2023
2a74109
refactor the services
Jul 28, 2023
3fb66f2
reload the systemd daemon before enabling the services
Jul 28, 2023
820717c
renam the debian directory
Jul 28, 2023
551d30a
add changelog to track changes to the package
Jul 28, 2023
7a46940
the package control directory should be lowercase
Jul 28, 2023
15a0219
add shebang to the changelog
Jul 28, 2023
a3837e8
changing the control file for the package.
Jul 28, 2023
4abb111
add the source for the control file.
Jul 28, 2023
e42bfb7
fix the service call
Jul 28, 2023
1f9bd45
add hithub action workflow to automate the package building process
Jul 28, 2023
d47a11b
fix Nested mappings
Jul 28, 2023
4eb5e5f
refactor the hithub action file
Jul 28, 2023
fab03a9
restructer the repo preparing for the packaging pipeline
Jul 29, 2023
722ce7d
updating the README file
Aug 1, 2023
34a97ae
create first action file
Aug 1, 2023
4354542
granting permession for all executables
Aug 1, 2023
5ac7025
updating the release token for github actions
Aug 1, 2023
8f77780
use env variables to change the release name
Aug 1, 2023
714441d
fix githube release token
Aug 1, 2023
5af3364
trigger the pipeline only with tags starts with v
Aug 1, 2023
00d069f
update the version in the control file
Aug 1, 2023
80aff10
update README.md file
Aug 1, 2023
0ef7f79
update README.md file
Aug 1, 2023
60bd5f2
update README.md file
Aug 1, 2023
7129a5d
add reboot msg
Aug 1, 2023
53d5d19
debig action file
Aug 1, 2023
28b80df
fix package permission
Aug 1, 2023
5f799b3
fix package permission
Aug 1, 2023
ff0f5ac
remove debugging lines and add fix broken install
Aug 1, 2023
f54edc8
fix installing dependencies
Aug 1, 2023
e548bb8
use QEMU to build the package for the arm64 architecture
Aug 1, 2023
5543f5f
use docker to Cross-Compile ARM64 the package
Aug 1, 2023
b0d2e0d
use conventional name for the package
Aug 2, 2023
a3735c5
create script for rendering the packages in different archs
Aug 2, 2023
87419d2
improve create-version.sh
Aug 2, 2023
98fe326
create a script to upload all versions to release
Aug 2, 2023
eecc743
modify the pipeline to create multi archs versions
Aug 2, 2023
00c72e6
fix typo
Aug 2, 2023
d52c1da
create prerm and post rm to controll in- and uninstall process
Aug 2, 2023
38d4770
fix script path in the pipeline
Aug 2, 2023
ae2351c
fix path in create-version script
Aug 2, 2023
c8e2142
debug path in create-version script
Aug 2, 2023
73f5a30
debug path in create-version script
Aug 2, 2023
94d4f68
fix create-version script
Aug 2, 2023
2e983fc
fix path for artifacts upload
Aug 2, 2023
e09b8b8
debug artifacts
Aug 2, 2023
22924b9
delete old step in actions
Aug 2, 2023
a42c334
update upload-artifacts.sh script
Aug 2, 2023
8f56cea
fix removal of pwm line from /boot/config.txt
Aug 2, 2023
264e321
standerizing terminate function
Aug 3, 2023
ea8e8ee
fix: typo
Aug 3, 2023
8eeafee
update the Arch type in debian control before build the package
Aug 4, 2023
645a16b
add pipeline step to modify changelog, version and ARCH before buildi…
Aug 4, 2023
ff9a601
fix changelog path in the script
Aug 4, 2023
32132c9
resetting the changelog file.
Aug 4, 2023
f638b10
add DEBFULLNAME, DEBEMAIL for dch package.
Aug 4, 2023
d83404b
fix typo
Aug 4, 2023
29c71af
use vars instead of secrets.
Aug 4, 2023
66341e2
fix dch command to use non-interactive shell
Aug 4, 2023
834739b
fix git push in the pipeline job
Aug 4, 2023
14d2e29
use the secret token to push the changes
Aug 4, 2023
13f4b8c
use ad-m/github-push-action to push the changes
Aug 4, 2023
8e07412
use push on th packaging-the-script branch to test
Aug 4, 2023
2d965a2
update git push command
Aug 4, 2023
b39570c
set remote url to use github token before push
Aug 4, 2023
6d99e26
fix git remote set-url
Aug 4, 2023
bcd0c74
using personal token when checkout the repo
Aug 5, 2023
659b514
fix typo in repo url
Aug 5, 2023
b2f7296
use temporarily a branch name to checkout.
Aug 5, 2023
2912be7
Update Changelog and Set Version to 3.0.0
molhamalnasr Aug 5, 2023
1fcd00c
get rid of the deprecated set-output command
Aug 5, 2023
2450c0a
fix appending to changerlog when exist.
Aug 5, 2023
8495dda
Update Changelog and Set Version to 3.0.0
molhamalnasr Aug 5, 2023
e6a95d6
fix output vars in github actions file
Aug 5, 2023
6e7c9b6
Merge branch 'packaging-the-script' of github.com:molhamalnasr/x735-s…
Aug 5, 2023
f74d986
reset changelog
Aug 5, 2023
83101e0
Update Changelog and Set Version to 3.0.0
molhamalnasr Aug 5, 2023
6438c5b
add outputs to the update_repo job
Aug 5, 2023
513a660
Update Changelog and Set Version to 3.0.0
molhamalnasr Aug 5, 2023
ed2ce8d
change installation command
Aug 5, 2023
90e2a40
Update Changelog and Set Version to 3.0.1
molhamalnasr Aug 5, 2023
cd084e8
add dynamic release note
Aug 6, 2023
00d3c0a
Update Changelog and Set Version to 3.0.0
molhamalnasr Aug 6, 2023
af4d7c9
update release note automaticallly for new releases
Aug 8, 2023
6080b33
Update Changelog and Set Version to 3.0.0
molhamalnasr Aug 8, 2023
3dd0bf3
fix script name in yaml file
Aug 8, 2023
508c120
Update Changelog and Set Version to 3.0.0
molhamalnasr Aug 8, 2023
530e9e4
fix release note template generator.
Aug 8, 2023
b228381
Update Changelog and Set Version to 3.0.0
molhamalnasr Aug 8, 2023
dc3f5f4
fix parsing json in release note.
Aug 8, 2023
d2166a9
Update Changelog and Set Version to 3.0.0
molhamalnasr Aug 8, 2023
339077e
update release note automatically after creating it
Aug 9, 2023
76ab280
Merge branch 'packaging-the-script' of github.com:molhamalnasr/x735-s…
Aug 9, 2023
0c1662e
reset changelog for initial release.
Aug 9, 2023
c5a58c6
update the readme file
Aug 9, 2023
4bd414b
update github action trigger
Aug 9, 2023
1eb4464
organising the pipeline logs with groups
Aug 12, 2023
0e116ae
fix link in README.md file
Aug 12, 2023
4bdcee5
update env variable name to avoide overwriting github default vars
Aug 12, 2023
42402c2
Merge branch 'packaging-the-script'
molhamalnasr Aug 12, 2023
670ecb5
fix the pipeline
Aug 12, 2023
3f95bc3
Merge branch 'packaging-the-script'
molhamalnasr Aug 12, 2023
3153915
Update Changelog and Set Version to 3.0.0
molhamalnasr Aug 12, 2023
bbe4a80
edit README
molhamalnasr Dec 25, 2023
8bd3fc8
Update Changelog and Set Version to 3.0.1
molhamalnasr Dec 25, 2023
1570284
fix the path for the config.txt file
molhamalnasr Jan 4, 2025
c9f4954
Merge pull request #1 from molhamalnasr/change-config.txt-path-for-bo…
molhamalnasr Jan 4, 2025
a864a05
update checkout repo and the changelog_msg
molhamalnasr Jan 4, 2025
f325e2c
Update Changelog and Set Version to 3.0.1
molhamalnasr Jan 4, 2025
d854d8e
update action deps versions
molhamalnasr Jan 4, 2025
e1e1055
Update Changelog and Set Version to 3.0.1
molhamalnasr Jan 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/bin/create-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

set -e

readonly PACKAGE_PATH="$1"
readonly CONTROL_PATH="$2"
readonly PACKAGE_VERSION="$3"
declare -a ARCH_LIST=("arm64" "armhf")

# Create the "versions" directory if it doesn't exist
mkdir -p ${PACKAGE_PATH}/versions

for arch_type in "${ARCH_LIST[@]}"; do
# first change the Architecture in the DEBIAN/control file
sed -i "/^Architecture:.*/ c Architecture: ${arch_type}" "${CONTROL_PATH}"

# Run docker image and build the package in the mounted directory
docker run --rm -v "$PACKAGE_PATH":/pkg multiarch/debian-debootstrap:"${arch_type}"-bullseye \
dpkg-deb --build /pkg/x735-script-pkg "/pkg/versions/x735-script_${PACKAGE_VERSION}_${arch_type}.deb"
done
84 changes: 84 additions & 0 deletions .github/workflows/bin/create_release_note.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash

set -e
set -o pipefail

readonly FILE_NOT_EXIST="152"
readonly INVALID_CLI_ARG_COUNT="154"
readonly INVALID_REQUEST="155"

terminate() {
local -r msg=$1
local -r err_code=${2:-150}
echo "${msg}" >&2
exit "${err_code}"
}

if [[ $# -ne 5 ]]; then
terminate "Usage: $0 TEMPLATE_FILE GITHUB_REPO TOKEN RELEASE_ID CHANGELOG_MSG" "${INVALID_CLI_ARG_COUNT}"
fi

readonly TEMPLATE_FILE_PATH=$1
readonly GITHUB_REPO=$2
readonly TOKEN=$3
readonly RELEASE_ID=$4
readonly CHANGELOG_MSG=$5

readonly release_url="https://api.github.com/repos/${GITHUB_REPO}/releases/${RELEASE_ID}"

# Check if the artifact path exists
if [ ! -s "$TEMPLATE_FILE_PATH" ]; then
terminate "Template release note not found or empty: ${TEMPLATE_FILE_PATH}" "${FILE_NOT_EXIST}"
fi

function convert_to_md_line_breaks() {
local input="$1"
local output=""
local IFS=$'\n'

for line in $input; do
output="${output}${line}\\n\\n"
done

echo "$output"
}

release_data=$(curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"${release_url}")

## check if data are JSON and the response is correct
if ! [[ "$release_data" =~ ^\{.*\}$ ]] || [[ ! $(echo "$release_data" | jq -e --arg RELEASE_ID "$RELEASE_ID" '.id == ($RELEASE_ID|tonumber)') ]]; then
terminate "The script was not able to pull release data." "${INVALID_REQUEST}"
fi

RELEASE_PUBLICH_DATE=$(echo "$release_data" | jq -r '.published_at')
TAG_NAME=$(echo "$release_data" | jq -r '.tag_name' | sed -n 's/^v//p')

readme_text=$(awk -v tag_name="${TAG_NAME}" -v release_date="$RELEASE_PUBLICH_DATE" -v repo="$GITHUB_REPO" -v msg="$CHANGELOG_MSG" '
{
gsub(/##TAG_NAME##/, tag_name);
gsub(/##RELEASE_DATE##/, release_date);
gsub(/##REPO##/, repo);
gsub(/##MSG##/, msg);
print;
}
' "$TEMPLATE_FILE_PATH")

release_text=$(convert_to_md_line_breaks "$readme_text")

send_release_note=$(curl -L \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-w "%{http_code}" \
-o /dev/null \
"${release_url}" \
-d "{\"body\":\"${release_text}\"}")

if [[ "$send_release_note" -ne "200" ]]; then
terminate "The script was not able to push release note." "${INVALID_REQUEST}"
fi
40 changes: 40 additions & 0 deletions .github/workflows/bin/update_changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

set -e

readonly CHANGELOG_PATH="$1"
readonly CHANGELOG_MSG="$2"
readonly VERSION="$3"

readonly INVALID_CLI_ARG_COUNT="154"

terminate() {
local -r msg=$1
local -r err_code=${2:-150}
echo "${msg}" >&2
exit "${err_code}"
}

# Check if commit message is not empty
if [ ! -n "$CHANGELOG_MSG" ]; then
terminate "Error: No commit message found in the trigger commit." "${INVALID_CLI_ARG_COUNT}"
fi

# Function to check if DEBIAN/changelog file exists
changelog_exists() {
[ -e "${CHANGELOG_PATH}" ]
}

# Function to create or append to DEBIAN/changelog
create_or_append_changelog() {
local message=$1

if changelog_exists; then
dch --package x735-script --newversion "${VERSION}" --changelog "${CHANGELOG_PATH}" -- "$message [v${VERSION}]"
else
dch --package x735-script --newversion "${VERSION}" --create --changelog "${CHANGELOG_PATH}" -- "Initial Release. [v${VERSION}]"
fi
}

# Main script
create_or_append_changelog "$CHANGELOG_MSG"
48 changes: 48 additions & 0 deletions .github/workflows/bin/upload-artifacts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

set -e

readonly FILE_NOT_EXIST="152"
readonly INVALID_CLI_ARG_COUNT="154"

terminate() {
local -r msg=$1
local -r err_code=${2:-150}
echo "${msg}" >&2
exit "${err_code}"
}

# Function to upload an artifact to the release
upload_artifact() {
local artifact_path=$1
local upload_url=$2
local token=$3

filename=$(basename "$artifact_path")
echo "Uploading $filename..."

curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${token}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Content-Type: application/octet-stream" \
"$upload_url=$filename" \
--data-binary "@${artifact_path}"
}

# Main script starts here
if [ $# -lt 3 ]; then
terminate "Usage: $0 <artifact_path> <upload_url> <token>" "${INVALID_CLI_ARG_COUNT}"
fi

artifact_path=$1
upload_url=$2
token=$3

# Check if the artifact path exists
if [ ! -f "$artifact_path" ]; then
terminate "Artifact file not found: ${artifact_path}" "${FILE_NOT_EXIST}"
fi

upload_artifact "$artifact_path" "$upload_url" "$token"
127 changes: 127 additions & 0 deletions .github/workflows/build-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: Build and Package Fan Board Script

on:
push:
tags:
- 'v*'

env:
WORKFLOW_PATH: ${GITHUB_WORKSPACE}/.github/workflows
PACKAGE_DEBIAN: ${GITHUB_WORKSPACE}/x735-script-pkg/DEBIAN
USER_NAME: ${{ vars.USER_NAME }}
USER_EMAIL: ${{ vars.USER_EMAIL }}

jobs:
update_repo:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: main
token: ${{ secrets.CREATE_RELEASE_TOKEN }}

- name: Install Dependencies
run: |
# Install any necessary dependencies for modifing the repository
sudo apt update && sudo apt install -y devscripts

- name: Set up Environment
id: update_repo_settings
run: |
git config --local user.name "${{ env.USER_NAME }}"
git config --local user.email "${{ env.USER_EMAIL }}"

# changelog message gonna be in this case the last commit message where the tag is created.
echo "changelog_msg=$(git log -1 --pretty=%B | head -n 1)" >> "$GITHUB_OUTPUT"
echo "tag_name=$(echo "${GITHUB_REF}" | sed -n 's|^refs/tags/v||p')" >> "$GITHUB_OUTPUT"

- name: Update and Commit Changelog
run: |
export DEBFULLNAME="${{ env.USER_NAME }}"
export DEBEMAIL="${{ env.USER_EMAIL }}"
/bin/bash ${{ env.WORKFLOW_PATH }}/bin/update_changelog.sh "${{ env.PACKAGE_DEBIAN }}/changelog" "${{ steps.update_repo_settings.outputs.changelog_msg }}" "${{ steps.update_repo_settings.outputs.tag_name }}"

- name: Update Version
run: |
sed -i '/^Version:.*/ c Version: ${{ steps.update_repo_settings.outputs.tag_name }}' "${{ env.PACKAGE_DEBIAN }}/control"

- name: Commit Changelog Changes
id: commit_changelog
run: |
git add .
git commit -m "Update Changelog and Set Version to ${{ steps.update_repo_settings.outputs.tag_name }}"
#git remote set-url --push origin "https://${{ secrets.CREATE_RELEASE_TOKEN }}@github.com/${{ github.repository }}.git"
git push --follow-tags origin main

# Store the commit SHA as an output variable
echo "update_repo_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"

outputs:
tag_name: ${{ steps.update_repo_settings.outputs.tag_name }}
update_repo_sha: ${{ steps.commit_changelog.outputs.update_repo_sha }}
changelog_msg: ${{ steps.update_repo_settings.outputs.changelog_msg }}



build_and_package:
runs-on: ubuntu-latest
needs: update_repo

steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ needs.update_repo.outputs.update_repo_sha }} # Use the update_repo_sha output from the previous job

- name: Install Dependencies
run: |
echo "Install any necessary dependencies for building your script here"
sudo apt update && sudo apt install -y dpkg qemu-user-static jq

- name: Set up QEMU for arm64
run: |
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

- name: Granting Permissions
run: |
# Grant execute permission to all files in DEBIAN directory, but the compat file
find ${{ env.PACKAGE_DEBIAN }} -type f ! -name 'compat' -exec chmod +x {} \;

- name: Build different ARCH Versions
run: |
# Run the create-version.sh script to build different versions
/bin/bash ${{ env.WORKFLOW_PATH }}/bin/create-version.sh "${GITHUB_WORKSPACE}" "${{ env.PACKAGE_DEBIAN }}/control" "${{ needs.update_repo.outputs.tag_name }}"

- name: Save Artifact
uses: actions/upload-artifact@v4
with:
name: x735-script-artifacts
path: versions/x735-script_*.deb

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.CREATE_RELEASE_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release Version ${{ needs.update_repo.outputs.tag_name }}
draft: false
prerelease: false

- name: Upload Artifacts to Release and update Release Note
run: |
# Update Release Note
/bin/bash ${{ env.WORKFLOW_PATH }}/bin/create_release_note.sh \
"${{ env.WORKFLOW_PATH }}/templates/release_template.txt" \
"${{ github.repository }}" \
"${{ secrets.CREATE_RELEASE_TOKEN }}" \
"${{ steps.create_release.outputs.id }}" \
"${{ needs.update_repo.outputs.changelog_msg }}"

# Add a loop to upload each artifact
for artifact in ${GITHUB_WORKSPACE}/versions/x735-script_*.deb; do
/bin/bash ${{ env.WORKFLOW_PATH }}/bin/upload-artifacts.sh "$artifact" "${{ steps.create_release.outputs.upload_url }}" "${{ secrets.CREATE_RELEASE_TOKEN }}"
done
Loading