Skip to content

Update package and restart service before anything #136

Update package and restart service before anything

Update package and restart service before anything #136

name: Create USB setup file
on:
schedule:
# Run every thursday at midnight
- cron: '0 0 * * THU'
pull_request:
push:
paths:
- download-packages.sh
- .github/workflows/download-packages.yml
branches:
- master
workflow_dispatch:
env:
MOUNT_POINT: "/tmp/pi-top-os"
jobs:
download-packages:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
include:
- DISTRO: "bullseye"
PI_TOP_OS_URL: "https://storage.googleapis.com/pt-os-release/pi-topOS-bullseye/pi-topOS_bullseye_release_armhf_2024-08-28_B66.zip"
PACKAGES_FOLDER_NAME: "updates"
COMPRESSED_UPDATES_FILENAME: "updates.tar.gz"
- DISTRO: "bookworm"
PI_TOP_OS_URL: "https://storage.googleapis.com/pt-os-release/pi-topOS-bookworm/pi-topOS_bookworm_release_armhf_2024-08-06_B62.zip"
PACKAGES_FOLDER_NAME: "updates_bookworm"
COMPRESSED_UPDATES_FILENAME: "updates_bookworm.tar.gz"
permissions:
contents: "read"
id-token: "write"
steps:
- name: Free disk space
uses: jlumbroso/free-disk-space@v1.3.1
with:
tool-cache: false
android: true
dotnet: true
haskell: true
large-packages: false
docker-images: false
swap-storage: false
- name: GitHub Environment Variables Action
uses: FranzDiebold/github-env-vars-action@v2.7.0
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install dependencies
run: |
sudo apt-get update && sudo apt-get install -y \
systemd-container \
qemu-user-static
- name: Get pi-topOS image filename
run: |
echo "IMAGE_FILE=$(basename ${{ matrix.PI_TOP_OS_URL }} | cut -d'.' -f1).img" >> $GITHUB_ENV
- name: Download pi-topOS image
run: |
wget "${{ matrix.PI_TOP_OS_URL }}" -O pi-topOS.zip
unzip pi-topOS.zip
- name: Mount OS Image root partition
uses: jcapona/mount-image-partition-action@v0.3
with:
imagePath: ${{ env.IMAGE_FILE }}
mountPoint: ${{ env.MOUNT_POINT }}
partitionIndex: 3
filesystem: ext4
- name: Update pi-topOS container and download packages
run: |
sudo systemd-nspawn --pipe --bind "$PWD":/packages -D "${{ env.MOUNT_POINT }}" /bin/bash << EOF
# Use /packages/tmp as a temporary directory to store the apt cache
mkdir -p /packages/tmp
mv -i /var/cache/apt /packages/tmp
ln -s /packages/tmp /var/cache/apt
# Update system and download packages
apt update
DEBIAN_FRONTEND=noninteractive apt dist-upgrade -y
cd /packages
ls -lh
bash ./download-packages.sh "${{ matrix.PACKAGES_FOLDER_NAME }}" "${{ matrix.COMPRESSED_UPDATES_FILENAME }}"
# Cleanup
apt-get clean
unlink /var/cache/apt
mv /packages/tmp/apt /var/cache
rm -rf /packages/tmp
EOF
- name: Delete OS image to save space
run: |
sudo umount "${{ env.MOUNT_POINT }}" || true
rm -f "${{ env.IMAGE_FILE }}"
- name: List downloaded packages
run: |
ls -lh "${{ matrix.PACKAGES_FOLDER_NAME }}"
- name: Compress downloaded packages
run: |
mkdir -p pi-top-usb-setup
sudo mv ${{ matrix.PACKAGES_FOLDER_NAME }} pi-top-usb-setup/
sudo chown -R $USER:$USER pi-top-usb-setup
sudo chmod -R 755 pi-top-usb-setup
tar -czvf pi-top-usb-setup-${{ matrix.DISTRO }}.tar.gz pi-top-usb-setup
sudo rm -rf pi-top-usb-setup
ls -lhR
- name: Upload as artifact
uses: actions/upload-artifact@v4
with:
name: files-${{ matrix.DISTRO }}
path: |
*.list
pi-top-usb-setup*.tar.gz
- name: Authenticate with GCP
uses: "google-github-actions/auth@v1.1.1"
if: github.ref == 'refs/heads/master'
with:
credentials_json: ${{ secrets.WEB_GCR_UPLOAD_KEY }}
- name: Upload to GCS
uses: google-github-actions/upload-cloud-storage@v1.0.3
if: github.ref == 'refs/heads/master'
with:
path: "."
glob: "pi-top-usb-setup-${{ matrix.DISTRO }}.tar.gz"
parent: false
destination: "${{ secrets.GCS_PACKAGES_UPLOAD_BUCKET }}/"
- name: Report to slack
if: github.ref == 'refs/heads/master' && always()
uses: slackapi/slack-github-action@v1.25.0
with:
channel-id: 'C02UEAAHK3R'
slack-message: "pi-top-Offline-Updates: create-usb-setup-file workflow run for ${{ matrix.DISTRO }}.\nStatus: ${{ job.status }}\nUrl: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_PACKAGE_PROMOTER_TOKEN }}
create-combined-bundle-file:
runs-on: ubuntu-20.04
needs: [download-packages]
steps:
- name: Download artifacts from previous job
uses: actions/download-artifact@v4
with:
pattern: files-*
- name: Extract files and combine them
run: |
mkdir -p pi-top-usb-setup
tar -xvf files-bullseye/pi-top-usb-setup-bullseye.tar.gz
tar -xvf files-bookworm/pi-top-usb-setup-bookworm.tar.gz
rm -rf files-*
tar -czvf pi-top-usb-setup.tar.gz pi-top-usb-setup
ls -lhR
rm -rf pi-top-usb-setup
- name: Upload as artifact
uses: actions/upload-artifact@v4
with:
name: files-all
path: |
pi-top-usb-setup.tar.gz
- name: Authenticate with GCP
uses: "google-github-actions/auth@v1.1.1"
if: github.ref == 'refs/heads/master'
with:
credentials_json: ${{ secrets.WEB_GCR_UPLOAD_KEY }}
- name: Upload to GCS
uses: google-github-actions/upload-cloud-storage@v1.0.3
if: github.ref == 'refs/heads/master'
with:
path: "."
glob: "pi-top-usb-setup.tar.gz"
parent: false
destination: "${{ secrets.GCS_PACKAGES_UPLOAD_BUCKET }}/"
- name: Report to slack
if: github.ref == 'refs/heads/master' && always()
uses: slackapi/slack-github-action@v1.25.0
with:
channel-id: 'C02UEAAHK3R'
slack-message: "pi-top-Offline-Updates: create-usb-setup-file workflow run for combined bundle.\nStatus: ${{ job.status }}\nUrl: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_PACKAGE_PROMOTER_TOKEN }}