diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 33928c4..a05bb97 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -6,6 +6,9 @@ on: pull_request: branches: [main] +permissions: + contents: read + jobs: python-lint-test: name: Python Lint and Test @@ -16,6 +19,17 @@ jobs: steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + + # tests/test_output.py validates the generated data, which lives in + # napari/plugin-api-data. Only the latest snapshot is needed. + - name: Check out napari/plugin-api-data into public/ + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + repository: napari/plugin-api-data + path: public + persist-credentials: false - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 023ceac..9d52bf7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,6 +16,16 @@ jobs: steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + + # The Next.js build reads the generated data, now in napari/plugin-api-data. + - name: Check out napari/plugin-api-data into public/ + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + repository: napari/plugin-api-data + path: public + persist-credentials: false - name: Set up Node.js ${{ matrix.node-version }} uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index 3dc08dc..23888d9 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -7,6 +7,11 @@ on: # "every 2 hours" - cron: 0 */2 * * * +# Two runs must never commit to napari/plugin-api-data at the same time. +concurrency: + group: update-plugin-index-${{ github.event_name == 'pull_request' && github.ref || 'data' }} + cancel-in-progress: false + jobs: fetch: name: Fetch @@ -20,6 +25,22 @@ jobs: steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + + # The generated JSON lives in napari/plugin-api-data. Check it out into + # public/, where every script reads and writes it. DATA_DEPLOY_KEY is a + # deploy key with write access to that repository only; without it (on + # pull requests from forks) the checkout is read-only, which is all a + # pull request needs. + # The deploy key must stay configured for the push at the end of the job. + # Only the built site is uploaded as an artifact, never public/.git. + - name: Check out napari/plugin-api-data into public/ + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 # zizmor: ignore[artipacked] + with: + repository: napari/plugin-api-data + path: public + ssh-key: ${{ secrets.DATA_DEPLOY_KEY }} - id: auth name: Authenticate to Google Cloud @@ -55,17 +76,21 @@ jobs: GH_API_TOKEN: ${{ secrets.GH_API_TOKEN }} CODECOV_API_TOKEN: ${{ secrets.CODECOV_API_TOKEN }} - # push changes back to the repo, this will trigger a new vercel build + # Invalid data is never committed or deployed. + - name: Validate the data + run: | + python -m pytest tests/test_output.py -q + + # Commit the new data to napari/plugin-api-data. Skip on PRs: they only + # validate. # https://github.com/stefanzweifel/git-auto-commit-action - # skip on PRs - we only want to validate, not modify the PR - uses: stefanzweifel/git-auto-commit-action@04702edda442b2e678b25b537cec683a1493fcb9 # v7.1.0 if: github.event_name != 'pull_request' with: + repository: public commit_message: '[bot] Update Plugin Index' commit_author: github-actions[bot] - # prepare static files for gh-pages deployment - # do this AFTER the vercel commit to make sure we're not messing with anything - name: Prepare gh-pages run: | python scripts/prepare_gh_pages.py diff --git a/.gitignore b/.gitignore index 3724fb2..ee4a1d8 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,6 @@ yarn-error.log* # Ignore generated credentials from google-github-actions/auth gha-creds-*.json *.pyc + +# generated data: a clone of napari/plugin-api-data (see CONTRIBUTING.md) +/public/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9c39e2b..1ef48e2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -35,7 +35,16 @@ source .venv/bin/activate python -m pip install -e ".[dev]" ``` -3. Run the development server +3. Get the data. The generated JSON lives in + [napari/plugin-api-data](https://github.com/napari/plugin-api-data). Clone + it into `public/`, where every script expects it. `--depth 1` fetches only + the latest snapshot; leave it out for the full history since 2022 (~230 MB): + +```bash +git clone --depth 1 https://github.com/napari/plugin-api-data public +``` + +4. Run the development server ```bash npm run dev ```