Skip to content

Check for updates

Check for updates #15

name: Check for updates
on:
schedule: # for scheduling to work this file must be in the default branch
- cron: "0 0 * * *" # run every day at midnight
workflow_dispatch: # can be manually dispatched under GitHub's "Actions" tab
env:
# email sets "github-actions[bot]" as commit author, see https://github.community/t/github-actions-bot-email-address/17204/6
GIT_USER_NAME: github-actions[bot]
GIT_USER_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com
FLATPAK_ID: com.artemis_rgb.Artemis
jobs:
flatpak-external-data-checker:
runs-on: ubuntu-latest
container:
image: bilelmoussaoui/flatpak-github-actions:freedesktop-23.08
options: --privileged
strategy:
matrix:
branch: [ main ] # list all branches to check
steps:
- name: Install requests, ruamel.yaml and yq
run: |
python -m ensurepip --upgrade
python -m pip install requests ruamel.yaml yq
- uses: actions/checkout@v4
with:
ref: ${{ matrix.branch }}
submodules: 'true'
- name: Check for Flatpak source updates via Flatpak External Data Checker
uses: docker://ghcr.io/flathub/flatpak-external-data-checker:latest
with:
args: --edit-only ${{ env.FLATPAK_ID }}.yml
- name: Attempt to update the Artemis git sources
run: |
./.github/scripts/update-manifest.py
- name: Verify if git was updated
id: is-updated
run: |
git config --global --add safe.directory /__w/com.artemis_rgb.Artemis/com.artemis_rgb.Artemis
git status -s -uno
[ -z "$(git status -s -uno)" ] || echo "updated=true" >> $GITHUB_OUTPUT
- name: Generate dotnet sources
if: steps.is-updated.outputs.updated
run: |
# Extract required information from the manifest
MANIFEST_FILE="${FLATPAK_ID}.yml"
echo "Parsing manifest file '$MANIFEST_FILE' to determine required Flatpak packages and ID..."
RUNTIME=$(yq e '.runtime' "$MANIFEST_FILE")
RUNTIME_VERSION=$(yq e '.["runtime-version"]' "$MANIFEST_FILE")
SDK=$(yq e '.sdk' "$MANIFEST_FILE")
SDK_EXTENSIONS=$(yq e '.["sdk-extensions"][]' "$MANIFEST_FILE" 2>/dev/null || echo "")
if [ -z "$RUNTIME" ] || [ -z "$RUNTIME_VERSION" ] || [ -z "$SDK" ] || [ -z "$FLATPAK_ID" ]; then
error "Failed to extract required fields (runtime, runtime-version, sdk, id) from manifest."
fi
REQUIRED_FLATPAK_PACKAGES=(
"$RUNTIME//$RUNTIME_VERSION"
"$SDK//$RUNTIME_VERSION"
)
# Add SDK extensions if any
if [ -n "$SDK_EXTENSIONS" ]; then
while IFS= read -r EXT; do
REQUIRED_FLATPAK_PACKAGES+=("$EXT//$RUNTIME_VERSION")
done <<< "$SDK_EXTENSIONS"
fi
# Function to check if a Flatpak package is installed
is_flatpak_installed() {
local package="$1"
flatpak info "$package" &> /dev/null
}
# Install missing Flatpak packages
for package in "${REQUIRED_FLATPAK_PACKAGES[@]}"; do
if is_flatpak_installed "$package"; then
echo "Flatpak package '$package' is already installed."
else
echo "Flatpak package '$package' is not installed. Installing..."
flatpak install -y flathub "$package" || error "Failed to install $package"
fi
done
./generate-sources.py
- name: Reset Flatpak manifest to pre-modified state
run: |
git checkout -- ${FLATPAK_ID}.yml
- name: Run the Artemis git source updates again
run: |
./.github/scripts/update-manifest.py
- name: Run Flatpak External Data Checker again and Open PR
uses: docker://ghcr.io/flathub/flatpak-external-data-checker:latest
env:
GIT_AUTHOR_NAME: Flatpak External Data Checker
GIT_COMMITTER_NAME: Flatpak External Data Checker
GIT_AUTHOR_EMAIL: ${{ env.GIT_USER_NAME }}
GIT_COMMITTER_EMAIL: ${{ env.GIT_USER_EMAIL }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: --update --never-fork ${{ env.FLATPAK_ID }}.yml