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

Centralize More Universal CI Actions #8

Merged
merged 6 commits into from
Feb 8, 2023

Conversation

rmartin16
Copy link
Member

@rmartin16 rmartin16 commented Feb 4, 2023

New CI Workflows

pre-commit-run

  • Runs pre-commit checks for an arbitrary repo.
  • pre-commit-source defaults to .[dev]; use pre-commit if the repo doesn't define a pinned version.
  • Example usage:
jobs:
  pre-commit:
    name: Pre-commit checks
    uses: beeware/.github/.github/workflows/pre-commit-run.yml@main
    with:
      pre-commit-source: './core[dev]'

towncrier-run

  • Runs tox -e towncrier-check for an arbitrary repo.
  • tox-source defaults to .[dev]; use tox if the repo doesn't define a pinned version.
  • Example usage:
jobs:
  towncrier:
    name: Check towncrier
    uses: beeware/.github/.github/workflows/towncrier-run.yml@main
    with:
      tox-source: './core[dev]'

package-python

  • Creates a Python package via tox -e package and uploads as an artifact named 'packages-<repo name>'.
  • Example usage:
jobs:
  package:
    name: Python Package
    uses: beeware/.github/.github/workflows/package-python.yml@main
    with:
      tox-source: './core[dev]'
      build-subdirectory: ${{ matrix.subdir }}
      distribution-path: '*/dist/*'
    strategy:
      matrix:
        subdir:
        - 'android'
        - 'cocoa'
        ...

verify-app-build

  • Builds an app for a target platform, format, and framework on a particular OS using the invoking repo.
  • runner-os and framework are required at minimum.
  • If target-platform and target-format are not explicitly define, then all apps compatible with the runner-os and framework are built.
    • Example usage:
jobs:
  verify-apps:
    name: Build apps
    uses: beeware/.github/.github/workflows/verify-app-build.yml@main
    with:
      python-version: ${{ matrix.python-version }}
      python-source: ${{ matrix.python-source }}
      runner-os: windows-latest
      framework: ${{ matrix.framework }}
      target-platform: windows
      target-format: VisualStudio
    strategy:
      fail-fast: false
      matrix:
        python-version: [ '3.8', '3.9', '3.10', '3.11' ]
        python-source: [ 'github', 'winstore' ]
        framework: ['toga', 'pyside2', 'pyside6', 'ppb']

install-briefcase

jobs:
  job-name:
  runs-on: ubuntu-latest
  steps:
    - name: Install Briefcase
      uses: beeware/.github/.github/actions/install-briefcase@main

ci worklfow for .github

  • Exercises each of the workflows in the context of where they will be used.
  • In practice, this should help detect issues with changes to these workflows before those issues surface in the downstream repos.
  • This also means additional repos should be added here when such repos implement these workflows.

Implementation PRs

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

@rmartin16 rmartin16 force-pushed the shared-ci branch 30 times, most recently from 8f40a7e to 9ea0e60 Compare February 5, 2023 18:15
@rmartin16
Copy link
Member Author

rmartin16 commented Feb 6, 2023

@freakboy3742, this should be ready for review now. I've got it working everywhere I think we need to use it.

Also, these scripts kinda grew organically as I was finding requirements for each repo....so fresh eyes may see the forest i can't see through all the trees right now.

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

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

Woof... that's a lot of changes and dependent PRs :-)

I've flagged a few questions and comments inline; many of them are clarifications for my own benefit to make sure I fully understand what is going on; but broadly speaking, this is going in the right direction (and should make our lives a whole lot easier... once we land the changes 😅).

I haven't fully reviewed all the downstream repos yet - I've been working on the theory that we need to get this one right first, then get the other repos to be consistent with whatever lands. So - my comments here are mostly about the API surface and operation, guided by what I can see as the pre-existing CI usage, and intended usage once this PR is in place.

That said - a couple of things that I noticed:

  1. In the downstream repos (esp. Briefcase and Toga), I can see you've updated the CI target, but not the package target; that will be pulling artefacts from the CI build, so it will be impacted by the name change on the package workflow.
  2. I can't see anywhere in the Briefcase config that hits the Windows store python builds - am I missing something?

.github/workflows/pre-commit-run.yml Show resolved Hide resolved
with:
python-version: ${{ inputs.python-version }}
cache: 'pip'
cache-dependency-path: '**/setup.cfg'
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we might want to add pyproject.toml and setup.py to this list as well. We're still using setup.py in toga; I imagine that a move to full pyproject.toml format in the future is inevitable (either as part of a setuptools upgrade, or a move to hatch), so including those files would seem like a good protective mechanism.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added **/pyproject.toml as a path.

with:
python-version: ${{ inputs.python-version }}
cache: 'pip'
cache-dependency-path: '**/setup.cfg'
Copy link
Member

Choose a reason for hiding this comment

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

As above - do we want to add pyproject.toml and setup.py to this list?

Copy link
Member Author

@rmartin16 rmartin16 Feb 7, 2023

Choose a reason for hiding this comment

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

So....this starts to get a little tricky. The setup-python action hard errors if the files specified here don't exist. I'll give it a go and see if all the repos have these files.

(On a related note, this is why some of the other uses of setup-python don't/can't use this built in caching.)

Copy link
Member

Choose a reason for hiding this comment

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

I can save you the trouble; pyproject should exist everywhere (and if it doesn't, that's a bug); setup.py currently does, but should be slowly disappearing. (I've deleted it in the deb PR branch, for example).

Copy link
Member

Choose a reason for hiding this comment

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

Oh - and the template repositories won't have any of these files - but then, we won't be building Python packages for those repos.

Copy link
Member Author

Choose a reason for hiding this comment

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

The tests finished after I added pyproject.toml alongside setup.cfg.

@@ -0,0 +1,80 @@
name: Create Python Package
Copy link
Member

Choose a reason for hiding this comment

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

The "package-python" name is a little misleading... at the very least, it's "Python-package"; but if it's a beeware project, it's going to be Python regardless.

Copy link
Member Author

@rmartin16 rmartin16 Feb 7, 2023

Choose a reason for hiding this comment

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

That's definitely fair.

With that, GitHub currently has a limitation requiring all workflows to exist in the .github/workflows/ directory. So, while we may not end up with too many workflows, I was looking for a way for workflows related to the same thing/tool/concept to sort well alphabetically. That's why I started the workflows for pre-commit with pre-commit and same with towncrier. This leads, though, to a bit of awkward grammar with the action word coming last.

With that in mind, perhaps package-beeware-create.yml best follows those rules (although equally awkward)....and perhaps where a workflow like package-beeware-deploy.yml could theoretically exist alongside it...

Copy link
Member Author

Choose a reason for hiding this comment

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

Landed on python-package-create.yml.


inputs:
briefcase-url:
description: 'URL to Briefcase git repository.'
Copy link
Member

Choose a reason for hiding this comment

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

We've been trying to converge on " rather than ' in config files (for broad consistency with black); is there a particular reason you've reverted a bunch of those changes and moved to '?

Copy link
Member Author

Choose a reason for hiding this comment

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

Mostly because " and ' have different functional meanings in YAML....while in Python they are functionally equivalent.

Double quoted strings in YAML pass through a level of escape parsing that single quotes strings do not. So, really, I'm trying to emphasize that I literally want the value between the two single quotes without any interpretation.

That said, none of this is particularly consistent. For instance, all the places that GitHub is substituting values for ${{ github.event_name }} (and the like), practically none of those are quoted at all.

So, unless this is compelling, I'm fine converging on double quotes. I also just realized that I was confusing TOML with YAML; TOML is a bit more restrictive about double quotes...

.github/actions/install-briefcase/action.yml Show resolved Hide resolved
run: python -m pip install dist/briefcase-*.whl

- name: Install Briefcase
if: endsWith(inputs.repository, 'briefcase') != true
Copy link
Member

Choose a reason for hiding this comment

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

Is this not just !endWith...?

Copy link
Member Author

Choose a reason for hiding this comment

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

definitely is....my brain didn't want to believe ! was supported or something...

Updated.

Copy link
Member Author

@rmartin16 rmartin16 Feb 7, 2023

Choose a reason for hiding this comment

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

interestingly....GitHub allows endsWith(inputs.repository, 'briefcase') != true but requires the brackets for ${{ !endsWith(inputs.repository, 'briefcase') }}....hmm...

.github/workflows/verify-app-build.yml Outdated Show resolved Hide resolved
.github/actions/install-briefcase/action.yml Show resolved Hide resolved
@rmartin16 rmartin16 force-pushed the shared-ci branch 3 times, most recently from 97893cc to 4b8d858 Compare February 7, 2023 04:16
@rmartin16
Copy link
Member Author

I haven't fully reviewed all the downstream repos yet - I've been working on the theory that we need to get this one right first, then get the other repos to be consistent with whatever lands. So - my comments here are mostly about the API surface and operation, guided by what I can see as the pre-existing CI usage, and intended usage once this PR is in place.

This is definitely the approach I intend.

That said - a couple of things that I noticed:

  1. In the downstream repos (esp. Briefcase and Toga), I can see you've updated the CI target, but not the package target; that will be pulling artefacts from the CI build, so it will be impacted by the name change on the package workflow.

I think you're talking about, e.g. the release.yml in Briefcase where it download the uploaded package. That's definitely a good point. This is one of my weaker areas in understanding about the CI processes.

Reviewing release.yml, it runs ci.yml and then creates a release with the produced artifact. Based on that, I think I'll update Briefcase's ci.yml to propagate the artifact-name output from python-package-create.yml so release.yml can use it.

  1. I can't see anywhere in the Briefcase config that hits the Windows store python builds - am I missing something?

There's still the extra include to run Briefcase unit tests against one version of Windows Store Python:

        # Run tests against the latest Windows Store Python
        - platform: "windows"
          python-version: "winstore"
          experimental: false

@rmartin16
Copy link
Member Author

rmartin16 commented Feb 7, 2023

I removed the testing code last night that was allowing app-build-verify.yml to work from the branch for this PR. So, I'll need to wait until this is merged to finish updating the dependent PRs.

    - name: Checkout beeware/.github
      uses: actions/checkout@v3.3.0
      with:
        repository: "beeware/.github"
        path: "beeware-.github"

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

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

I picked up a couple of minor whitespace issues which I've pushed; but otherwise, I think this is good to go.

@rmartin16
Copy link
Member Author

ohh. interesting....well, I've added .pre-commit-config.yaml to the other PRs....probably should have done that here as well.

@freakboy3742
Copy link
Member

I haven't merged yet - so if there's something else you want to squeeze in here, I can hold off...

@rmartin16
Copy link
Member Author

All right. Added the same basic .pre-commit-config.yaml I put in the other repos.

@freakboy3742 freakboy3742 merged commit 83927d1 into beeware:main Feb 8, 2023
@rmartin16 rmartin16 deleted the shared-ci branch February 8, 2023 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants