Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT - CI improvements (security and maintenance) #2077

Merged
merged 54 commits into from
Mar 4, 2025

Conversation

trallard
Copy link
Collaborator

@trallard trallard commented Dec 12, 2024

I thought I would do some winter/summer cleaning (depending on your location) β›„πŸŒž.

This PR adds several improvements/updates to our CI with a focus on improving the contributor experience and security
Details below:

πŸ”’ Security focused

  • Use SHA for third-party actions and our internal action for development setup
  • Replace potentially dangerous trigger workflow_run for workflow_call and use as a reusable workflow
  • Create and use a dedicated environment for releases:
    • Created a pst-release environment in the repo (restricted to main only)
    • Use pst-release for our release-PST step in publish.yml
    • Add pst-release as the default env in PyPI
  • Add a zizmor.yml workflow to run static analysis on our GH workflows
  • Add explicit persist-credentials: false to relevant actions (where we do not need further git operations)

πŸ‘©πŸ½β€πŸŽ€ Contributor experience

  • Prevent the pre-release.yml workflow from running in repos not under the pydata org (forks)
  • Our CI workflow has grown significantly with the various tests and checks. This PR splits it into:
  • CI.yml: pytest, a11y-tests, profiling, coverage
  • docs.yml: docs-related checks like building across OSes and Python and Sphinx versions, check for broken links (new, note that I had to fix some broken links to get this in πŸ™ˆ and there seem to be still some others to fix)
  • Add tox run -e docs-linkcheck to check for broken links in our docs
  • Add workflow to add a link to the RTD docs preview in PRs.

🧰 Maintenance

  • Adds Python 3.13 to our testing matrices (3.12 is left as the default until we are confident all is ok with 3.13)
  • Add an explicit ubuntu-22.04 target as ubuntu-latest will soon be 24.04 (being rolled out right now) -> I think I might actually have explicit versions on both and only change to latest (or not) when the rollout is completed

Questions / notes

  • @drammock, we have "sphinx-theme-builder @ https://github.com/pradyunsg/sphinx-theme-builder/archive/87214d0671c943992c05e3db01dca997e156e8d6.zip", in our project. tool and tox.ini. I do not believe this pin is needed anymore, so I would like to remove it, too. WDYT?
  • @drammock did you create the token for Anaconda.org? I would like to make this an environment secret (vs a repository secret as it is right now)
  • Also, while adding a new environment, I noticed a github-pages environment that I do not think we are using, so I'd like to delete it.
  • Finally, I deleted a leftover PYPI_TOKEN, which should have been removed when we changed to trusted publishers.

Closes #2095

@trallard trallard added kind: maintenance Improving maintainability and reducing technical debt tag: CI Pull requests that update GitHub Actions code labels Dec 12, 2024
@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

Copy link

github-actions bot commented Dec 12, 2024

Coverage report

This PR does not seem to contain any modification to coverable code.

runs-on: ubuntu-latest
needs: [build-package]
permissions:
id-token: write # needed for PyPI upload
environment:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double-checking that this GitHub Environment is required on the Trusted Publisher in PyPI?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it to my checklist so I remember to add it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double-checking that this GitHub Environment is required on the Trusted Publisher in PyPI?

did this get done @trallard? If so please resolve the conversation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, since I did not know when we would merge this I did not want to enforce the env just in case we needed to do a release before this was merged (so the release would have failed).
Will do this change when we merge this PR.

@drammock
Copy link
Collaborator

@drammock, we have "sphinx-theme-builder @ https://github.com/pradyunsg/sphinx-theme-builder/archive/87214d0671c943992c05e3db01dca997e156e8d6.zip", in our project. tool and tox.ini. I do not believe this pin is needed anymore, so I would like to remove it, too. WDYT?

my fixes to STB were done in May and August of 2023, and the most recent release was March 2023. So we do still need the pin (or to install from tip of main would be fine too --- or convince Pradyun to cut a release πŸ˜„).
https://github.com/pradyunsg/sphinx-theme-builder/commits/main/

@drammock did you create the token for Anaconda.org? I would like to make this an environment secret (vs a repository secret as it is right now)

I don't remember creating it. But it might have been me. Are we pushing nightlies to the scientific python channel or something, is that what it's used for?

@trallard
Copy link
Collaborator Author

@drammock yes we are using the Scientific Python channel so I am pretty confident it was you then.

my fixes to STB were done in May and August of 2023, and the most recent release was March 2023. So we do still need the pin (or to install from tip of main would be fine too --- or convince Pradyun to cut a release πŸ˜„).
pradyunsg/sphinx-theme-builder@main (commits)

ha! I can do both, use main for now and bug Pradyun (I am pretty good at the latter now)

@trallard
Copy link
Collaborator Author

Ok I have removed Windows from the a11y CI as there were some failures that I am not sure are true accessibility fails but something else. Since this PR has been opened for a while it might be best to investigate these separately and re-add them, but for now we have a better matrix for a11y tests.

@drammock could you give this PR a last check and see if we can merge?

@trallard
Copy link
Collaborator Author

Note that the linkcheck is failing with community/inspiration.md:46: [broken] https://www.docker.com/wp-content/uploads/2022/03/vertical-logo-monochromatic.png: 404 Client Error: Not Found for url: https://www.docker.com/wp-content/uploads/2022/03/vertical-logo-monochromatic.png as it seems this has moved permanently.

I could not find a 1:1 alternative so I am not sure if the best option is to download and add the logo or something else.

@drammock
Copy link
Collaborator

Note that the linkcheck is failing with community/inspiration.md:46: [broken] https://www.docker.com/wp-content/uploads/2022/03/vertical-logo-monochromatic.png: 404 Client Error: Not Found for url: https://www.docker.com/wp-content/uploads/2022/03/vertical-logo-monochromatic.png as it seems this has moved permanently.

I could not find a 1:1 alternative so I am not sure if the best option is to download and add the logo or something else.

Fixed in #2141. According to Docker docs, the plain logo without wordmark is intended to replace the previous "stacked" logo+wordmark.

runs-on: ubuntu-latest
needs: [build-package]
permissions:
id-token: write # needed for PyPI upload
environment:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double-checking that this GitHub Environment is required on the Trusted Publisher in PyPI?

did this get done @trallard? If so please resolve the conversation.

trallard added a commit that referenced this pull request Mar 4, 2025
- addresses the missing Docker logo discovered in
#2077 (comment)
(stores SVG in our repo)
- updates GitBook logo (stores SVG in our repo)
- updates metaflow and mkdocs material URLs
- adds some basic CSS to that gallery grid (otherwise docker logo has no
padding around it, violates their brand guidelines)

Co-authored-by: Tania Allard <[email protected]>
Copy link
Collaborator Author

@trallard trallard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I have now addressed all the comments by @drammock and the last CI run was all green after merging the PR to fix the Docker logo link.

Comment on lines +64 to +80
- name: "Get PST version"
run: |
python -Im pip install -e .
# Get the version of the package
PST_VERSION=$(python -c "import pydata_sphinx_theme; print(pydata_sphinx_theme.__version__)")
echo "PST_VERSION=$PST_VERSION" >> $GITHUB_ENV

# Run tests on the built package (which will be later uploaded to PyPI)
- name: "Install PST from wheel and test"
env:
BAIPP_DIST: ${{ steps.baipp.outputs.dist }}
PST_VERSION: ${{ env.PST_VERSION }}
run: |
# calling with --installpkg so we can use the already built package
tox run -e py312-tests-no-cov \
--installpkg "${BAIPP_DIST}"/pydata_sphinx_theme-"${PST_VERSION}"-py3-none-any.whl \
-- --deselect tests/test_build.py::test_translations
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this extra test run. This would have caught the issues reported in #2090 for example

@trallard
Copy link
Collaborator Author

trallard commented Mar 4, 2025

I have noticed some flaky accessibility tests re tab traps (notebooks), I wonder if https://github.com/pydata/pydata-sphinx-theme/actions/runs/13659445744/job/38186908516#step:4:672 is related to #2139 (comment) at all @gabalafou

# needed for the coverage action
permissions:
contents: write
pull-requests: write
# calls our docs workflow (build docs, check broken links, lighthouse)
# calls our docs workflow (build docs, check broken links, lighthouse)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this indentation looks wrong, but I'll assume it was a linter autofix and not bother trying to put it back. Intent is pretty clear either way.

@drammock drammock merged commit 4a1e789 into pydata:main Mar 4, 2025
30 of 31 checks passed
@trallard trallard deleted the trallard/maintenance-ql-improvements branch March 5, 2025 10:06
@trallard
Copy link
Collaborator Author

trallard commented Mar 6, 2025

Final update I just updated the environment in PyPI so this will be the one used when doing the release (via trusted publisher)

drammock pushed a commit that referenced this pull request Mar 6, 2025
This follows #2077 as
our actions and workflows needed re-pinning after merging this branch.
Included:

- **:pushpin: Pin our actions to a concrete SHA**
- **:construction_worker: Add test to publish workflow**
gabalafou pushed a commit to gabalafou/pydata-sphinx-theme that referenced this pull request Mar 10, 2025
- addresses the missing Docker logo discovered in
pydata#2077 (comment)
(stores SVG in our repo)
- updates GitBook logo (stores SVG in our repo)
- updates metaflow and mkdocs material URLs
- adds some basic CSS to that gallery grid (otherwise docker logo has no
padding around it, violates their brand guidelines)

Co-authored-by: Tania Allard <[email protected]>
gabalafou pushed a commit to gabalafou/pydata-sphinx-theme that referenced this pull request Mar 10, 2025
I thought I would do some winter/summer cleaning (depending on your
location) β›„πŸŒž.

This PR adds several improvements/updates to our CI with a focus on
improving the contributor experience and security
Details below:

## πŸ”’ Security focused

- Use SHA for third-party actions and our internal action for
development setup
- Replace potentially [dangerous trigger
`workflow_run`](https://woodruffw.github.io/zizmor/audits/#dangerous-triggers)
for `workflow_call` and use as a reusable workflow
- Create and use a dedicated environment for releases: 
- [x] Created a `pst-release` environment in the repo (restricted to
`main` only)
  - [x] Use `pst-release` for our `release-PST` step in `publish.yml`
  - [ ] Add `pst-release` as the default env in PyPI
- Add a `zizmor.yml` workflow to run static analysis on our GH workflows
- Add explicit `persist-credentials: false` to relevant actions (where
we do not need further git operations)

## πŸ‘©πŸ½β€πŸŽ€ Contributor experience

- Prevent the `pre-release.yml` workflow from running in repos not under
the `pydata` org (forks)
- Our CI workflow has grown significantly with the various tests and
checks. This PR splits it into:
 -  `CI.yml`: pytest, a11y-tests, profiling, coverage
- `docs.yml`: docs-related checks like building across OSes and Python
and Sphinx versions, check for broken links (new, note that I had to fix
some broken links to get this in πŸ™ˆ and there seem to be still some
others to fix)
- Add `tox run -e docs-linkcheck` to check for broken links in our docs
- Add workflow to add a link to the RTD docs preview in PRs.

## 🧰 Maintenance

- Adds Python `3.13` to our testing matrices (`3.12` is left as the
`default` until we are confident all is ok with `3.13`)
- Add an explicit `ubuntu-22.04` target as `ubuntu-latest` will soon be
`24.04` (being rolled out right now) -> I think I might actually have
explicit versions on both and only change to latest (or not) when the
rollout is completed

----

## Questions / notes

- @drammock, we have `"sphinx-theme-builder @
https://github.com/pradyunsg/sphinx-theme-builder/archive/87214d0671c943992c05e3db01dca997e156e8d6.zip",`
in our `project. tool` and `tox.ini`. I do not believe this pin is
needed anymore, so I would like to remove it, too. WDYT?
- @drammock did you create the token for Anaconda.org? I would like to
make this an environment secret (vs a repository secret as it is right
now)
- Also, while adding a new environment, I noticed a `github-pages`
environment that I do not think we are using, so I'd like to delete it.
- Finally, I deleted a leftover `PYPI_TOKEN,` which should have been
removed when we changed to trusted publishers.
 
Closes pydata#2095

---------

Co-authored-by: Daniel McCloy <[email protected]>
gabalafou pushed a commit to gabalafou/pydata-sphinx-theme that referenced this pull request Mar 10, 2025
This follows pydata#2077 as
our actions and workflows needed re-pinning after merging this branch.
Included:

- **:pushpin: Pin our actions to a concrete SHA**
- **:construction_worker: Add test to publish workflow**
drammock pushed a commit that referenced this pull request Mar 12, 2025
This is a follow-up to #2077. This PR fixes action permissions to call
reusable workflows in our release workflow.

I also pinned the SHA for a workflow I missed in a previous review.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: maintenance Improving maintainability and reducing technical debt tag: CI Pull requests that update GitHub Actions code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update CI to run a11y tests on more browser / OS combos
3 participants