mirror of
https://github.com/dgtlmoon/changedetection.io.git
synced 2026-10-25 16:18:32 +00:00
* ci: pin third party actions to commit SHAs A tag or branch ref is a movable pointer, whoever controls the action repository can repoint it and the next run executes their code with this repo's secrets, here the Docker Hub tokens and the container publish path. The March 2025 tj-actions/changed-files incident (CVE-2025-30066) worked exactly that way. Each pin keeps the resolved tag in a comment and dependabot's weekly github-actions config bumps SHA pins like tags, so they self-maintain. The pypi publish action moves from the floating release/v1 branch to its current release. * ci: declare least-privilege workflow permissions Without a permissions block every job token inherits the repository default scope. Each workflow now declares what it uses. The test and build workflows get read-only tokens, CodeQL keeps its code scanning upload, the container publish job keeps packages write for the ghcr push, and the pypi publish job already carried its own id-token block for trusted publishing, untouched. * ci: pass release metadata to inline scripts through env The two debug steps interpolated the release tag name and the workflow_run branch directly into bash. Those strings are event metadata that can carry shell syntax, and the workflow runs on release events with the publish credentials in reach. Routed through env they arrive as plain data, output unchanged. * ci: stop persisting the checkout token in .git/config actions/checkout writes the job token into .git/config so later steps can push. None of these 21 jobs push with git: the containers are published with registry credentials, PyPI uses trusted publishing, and the test and CodeQL jobs only read the tree. A token left in .git/config is one more credential for a compromised step or a packed artifact to pick up, so each checkout now sets persist-credentials: false.
108 lines
3.1 KiB
YAML
108 lines
3.1 KiB
YAML
name: Publish Python 🐍distribution 📦 to PyPI and TestPyPI
|
|
|
|
on: push
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
build:
|
|
name: Build distribution 📦
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- uses: actions/checkout@v7
|
|
with:
|
|
persist-credentials: false
|
|
- name: Set up Python
|
|
uses: actions/setup-python@v7
|
|
with:
|
|
python-version: "3.11"
|
|
- name: Install pypa/build
|
|
run: >-
|
|
python3 -m
|
|
pip install
|
|
build
|
|
--user
|
|
- name: Build a binary wheel and a source tarball
|
|
run: python3 -m build
|
|
- name: Store the distribution packages
|
|
uses: actions/upload-artifact@v7
|
|
with:
|
|
name: python-package-distributions
|
|
path: dist/
|
|
|
|
|
|
test-pypi-package:
|
|
name: Test the built package works basically.
|
|
runs-on: ubuntu-latest
|
|
needs:
|
|
- build
|
|
steps:
|
|
- name: Download all the dists
|
|
uses: actions/download-artifact@v8
|
|
with:
|
|
name: python-package-distributions
|
|
path: dist/
|
|
- name: Set up Python 3.11
|
|
uses: actions/setup-python@v7
|
|
with:
|
|
python-version: '3.11'
|
|
|
|
- name: Test that the basic pip built package runs without error
|
|
run: |
|
|
set -ex
|
|
ls -alR
|
|
|
|
# Install the first wheel found in dist/
|
|
WHEEL=$(find dist -type f -name "*.whl" -print -quit)
|
|
echo Installing $WHEEL
|
|
python3 -m pip install --upgrade pip
|
|
python3 -m pip install "$WHEEL"
|
|
changedetection.io -d /tmp -p 10000 &
|
|
|
|
sleep 3
|
|
curl --retry-connrefused --retry 6 http://127.0.0.1:10000/static/styles/pure-min.css >/dev/null
|
|
curl --retry-connrefused --retry 6 http://127.0.0.1:10000/ >/dev/null
|
|
|
|
# --- API test ---
|
|
# This also means that the docs/api-spec.yml was shipped and could be read
|
|
test -f /tmp/changedetection.json
|
|
API_KEY=$(jq -r '.. | .api_access_token? // empty' /tmp/changedetection.json)
|
|
echo Test API KEY is $API_KEY
|
|
curl -X POST "http://127.0.0.1:10000/api/v1/watch" \
|
|
-H "x-api-key: ${API_KEY}" \
|
|
-H "Content-Type: application/json" \
|
|
--show-error --fail \
|
|
--retry 6 --retry-delay 1 --retry-connrefused \
|
|
-d '{
|
|
"url": "https://example.com",
|
|
"title": "Example Site Monitor",
|
|
"time_between_check": { "hours": 1 }
|
|
}'
|
|
|
|
killall changedetection.io
|
|
|
|
|
|
publish-to-pypi:
|
|
name: >-
|
|
Publish Python 🐍 distribution 📦 to PyPI
|
|
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
|
|
needs:
|
|
- test-pypi-package
|
|
runs-on: ubuntu-latest
|
|
environment:
|
|
name: release
|
|
url: https://pypi.org/p/changedetection.io
|
|
permissions:
|
|
id-token: write # IMPORTANT: mandatory for trusted publishing
|
|
|
|
steps:
|
|
- name: Download all the dists
|
|
uses: actions/download-artifact@v8
|
|
with:
|
|
name: python-package-distributions
|
|
path: dist/
|
|
- name: Publish distribution 📦 to PyPI
|
|
uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2
|