185 lines
5.8 KiB
YAML
185 lines
5.8 KiB
YAML
name: Wallpaper Changer CI
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
on:
|
|
workflow_run:
|
|
workflows:
|
|
- Serverlibrary CI
|
|
types:
|
|
- completed
|
|
push:
|
|
paths:
|
|
- "wallpaper_changer/python/**"
|
|
- ".gitea/workflows/**"
|
|
pull_request:
|
|
paths:
|
|
- "wallpaper_changer/python/**"
|
|
- ".gitea/workflows/**"
|
|
|
|
jobs:
|
|
test-wallpaper-changer:
|
|
if: >-
|
|
${{ github.event_name != 'workflow_run'
|
|
|| github.event.workflow_run.conclusion == 'success' }}
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: nikolaik/python-nodejs:python3.12-nodejs20
|
|
|
|
steps:
|
|
- name: Check out the tested commit
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github.sha }}
|
|
|
|
- name: Install serverlibrary and wallpaper_changer
|
|
working-directory: wallpaper_changer/python
|
|
run: |
|
|
python -m pip install --upgrade pip
|
|
python -m pip install ../../serverlibrary
|
|
python -m pip install --group test .
|
|
|
|
- name: Run wallpaper_changer tests
|
|
working-directory: wallpaper_changer/python
|
|
run: python tests/run_tests.py all
|
|
|
|
lint-wallpaper-changer:
|
|
if: >-
|
|
${{ github.event_name != 'workflow_run'
|
|
|| github.event.workflow_run.conclusion == 'success' }}
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: nikolaik/python-nodejs:python3.12-nodejs20
|
|
|
|
steps:
|
|
- name: Check out the tested commit
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github.sha }}
|
|
|
|
- name: Install Ruff
|
|
run: python -m pip install ruff
|
|
|
|
- name: Lint wallpaper_changer
|
|
run: ruff check wallpaper_changer/python
|
|
|
|
build:
|
|
if: >-
|
|
${{ github.event_name != 'workflow_run'
|
|
|| github.event.workflow_run.conclusion == 'success' }}
|
|
needs:
|
|
- test-wallpaper-changer
|
|
- lint-wallpaper-changer
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: nikolaik/python-nodejs:python3.12-nodejs20
|
|
|
|
steps:
|
|
- name: Check out the tested commit
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github.sha }}
|
|
|
|
- name: Install build dependencies
|
|
working-directory: wallpaper_changer/python
|
|
run: |
|
|
python -m pip install --upgrade pip
|
|
python -m pip install ../../serverlibrary
|
|
python -m pip install --group test .
|
|
python -m pip install build
|
|
|
|
- name: Build executable
|
|
working-directory: wallpaper_changer/python
|
|
run: |
|
|
python -m PyInstaller \
|
|
--clean \
|
|
--onefile \
|
|
--paths src \
|
|
--name wallpaper_changer \
|
|
main.py
|
|
|
|
- name: Build wheel
|
|
working-directory: wallpaper_changer/python
|
|
run: python -m build --wheel
|
|
|
|
- name: Verify build outputs
|
|
working-directory: wallpaper_changer/python
|
|
run: |
|
|
ls -lh dist/
|
|
test -f dist/wallpaper_changer
|
|
ls dist/*.whl
|
|
|
|
- name: Upload build artifacts
|
|
uses: https://github.com/christopherHX/gitea-upload-artifact@v4
|
|
with:
|
|
name: wallpaper-changer-build
|
|
path: wallpaper_changer/python/dist/
|
|
if-no-files-found: error
|
|
|
|
install:
|
|
if: >-
|
|
${{ (github.event_name == 'push'
|
|
&& github.ref == 'refs/heads/main')
|
|
|| (github.event_name == 'workflow_run'
|
|
&& github.event.workflow_run.conclusion == 'success') }}
|
|
needs: build
|
|
runs-on: [self-hosted, linux, x64]
|
|
|
|
steps:
|
|
- name: Download build artifacts
|
|
uses: https://github.com/christopherHX/gitea-download-artifact@v4
|
|
with:
|
|
name: wallpaper-changer-build
|
|
path: dist/
|
|
|
|
- name: Install executable and provision private key
|
|
env:
|
|
WALLPAPER_PRIVATE_KEY_PEM: ${{ secrets.WALLPAPER_PRIVATE_KEY_PEM }}
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
validate_private_key() {
|
|
if [ "$(head -n 1 "$1")" != "-----BEGIN RSA PRIVATE KEY-----" ]; then
|
|
echo "Expected an unencrypted RSA PKCS#1 PEM private key." >&2
|
|
return 1
|
|
fi
|
|
openssl pkey -in "$1" -noout
|
|
}
|
|
|
|
key_dir="$HOME/.wallpaper"
|
|
key_file="$key_dir/private_key.pem"
|
|
install -d -m 700 "$key_dir"
|
|
|
|
if [ -L "$key_file" ] || { [ -e "$key_file" ] && [ ! -f "$key_file" ]; }; then
|
|
echo "Refusing to use a non-regular key path: $key_file" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [ -f "$key_file" ]; then
|
|
validate_private_key "$key_file"
|
|
chmod 600 "$key_file"
|
|
echo "Preserving the existing private key."
|
|
else
|
|
: "${WALLPAPER_PRIVATE_KEY_PEM:?Set the WALLPAPER_PRIVATE_KEY_PEM Gitea secret for first-time installation}"
|
|
temporary_key="$(mktemp "$key_dir/.private_key.XXXXXX")"
|
|
trap 'rm -f "$temporary_key"' EXIT
|
|
printf '%s' "$WALLPAPER_PRIVATE_KEY_PEM" > "$temporary_key"
|
|
validate_private_key "$temporary_key"
|
|
chmod 600 "$temporary_key"
|
|
if ln "$temporary_key" "$key_file"; then
|
|
echo "Installed the private key with mode 600."
|
|
elif [ -f "$key_file" ]; then
|
|
validate_private_key "$key_file"
|
|
chmod 600 "$key_file"
|
|
echo "Preserving the private key installed concurrently."
|
|
else
|
|
echo "Failed to install the private key." >&2
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
install -d -m 755 "$HOME/tools"
|
|
install -m 755 dist/wallpaper_changer "$HOME/tools/wallpaper_changer"
|