diff --git a/.github/workflows/qa.yaml b/.github/workflows/qa.yaml index 0c3e397..97c538c 100644 --- a/.github/workflows/qa.yaml +++ b/.github/workflows/qa.yaml @@ -5,26 +5,26 @@ on: pull_request: branches: [ "main" ] jobs: - make-versions: + python-versions: runs-on: ubuntu-latest outputs: - versions: ${{ steps.make-versions.outputs.versions }} + versions: ${{ steps.python-versions.outputs.versions }} steps: - uses: actions/checkout@v4 - - name: Make versions - id: make-versions + - name: Get Python versions + id: python-versions run: | - classifiers="$(yq -p toml -o toml '.project.classifiers[]' pyproject.toml | grep "Programming Language :: Python :: " | grep "\.")" - versions="$(echo "$classifiers" | sed -e 's/Programming Language :: Python :: \([0-9.]*\)$/"\1"/g' | tr '\n' ',' | sed -e 's/,$//g')" - echo "versions=[$versions]" > "$GITHUB_OUTPUT" + CLASSIFIERS="$(yq -p toml -o toml '.project.classifiers[]' pyproject.toml | grep "Programming Language :: Python :: " | grep "\.")" + VERSIONS="$(echo "${CLASSIFIERS}" | sed -e 's/Programming Language :: Python :: \([0-9.]*\)$/"\1"/g' | tr '\n' ',' | sed -e 's/,$//g')" + echo "versions=[${VERSIONS}]" > "${GITHUB_OUTPUT}" qa: name: Run QA checks runs-on: ubuntu-latest - needs: make-versions + needs: python-versions strategy: matrix: - python-version: ${{fromJson(needs.make-versions.outputs.versions)}} + python-version: ${{fromJson(needs.python-versions.outputs.versions)}} steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} @@ -48,3 +48,11 @@ jobs: npx pyright@latest - name: Run tests run: pytest ./tests + + actionlint: + name: Run actionlint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Run actionlint + uses: raven-actions/actionlint@v1 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..5226554 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,99 @@ +name: Release +on: + push: + tags: + - 'v*' +jobs: + versions: + runs-on: ubuntu-latest + outputs: + python-version: ${{ steps.python-version.outputs.python_version }} + release-version: ${{ steps.release-version.outputs.release_version }} + steps: + - uses: actions/checkout@v4 + - name: Get latest supported Python version + id: python-version + run: | + CLASSIFIERS="$(yq -p toml -o toml '.project.classifiers[]' pyproject.toml | grep "Programming Language :: Python :: " | grep "\.")" + VERSION="$(echo "${CLASSIFIERS}" | sed -e 's/Programming Language :: Python :: \([0-9.]*\)$/"\1"/g' | tail -n 1)" + echo "python_version=[${VERSION}]" > "${GITHUB_OUTPUT}" + # See: https://stackoverflow.com/questions/58177786/get-the-current-pushed-tag-in-github-actions + - name: Get release version + id: release-version + run: | + VERSION="$(yq -p toml -o toml -r '.project.version' pyproject.toml)" + echo "release_version=${VERSION}" >> "${GITHUB_OUTPUT}" + + build: + runs-on: ubuntu-latest + needs: + - versions + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ needs.versions.outputs.python-version }} + uses: actions/setup-python@v4 + with: + python-version: "${{ needs.versions.outputs.python-version }}" + - name: Install the world + run: | + python -m pip install --upgrade pip setuptools wheel + pip install -e .[dev] + - name: Build Package Distributions + run: python -m build + - name: Store Package Distributions + uses: actions/upload-artifact@v3 + with: + name: package-distributions + path: dist/ + - name: Build Man Page + run: sphinx-build -M man docs _build + - name: Store Man Page + uses: actions/upload-artifact@v3 + with: + name: man-page + path: _build/man + + pypi-release: + runs-on: ubuntu-latest + needs: + - build + environment: + name: pypi + url: https://pypi.org/p/pypi + permissions: + id-token: write + steps: + - name: Download distributions + uses: actions/download-artifact@v3 + with: + name: package-distributions + path: dist/ + - name: Publish release to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + + github-release: + runs-on: ubuntu-latest + needs: + - versions + - build + steps: + - name: Download distributions + uses: actions/download-artifact@v3 + with: + name: package-distributions + path: dist/ + - name: Download man page + uses: actions/download-artifact@v3 + with: + name: man-page + path: man + - name: Create a GitHub release + uses: marvinpinto/action-automatic-releases@latest + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + draft: false + prerelease: false + title: Release v${{ needs.versions.outputs.release-version }} + files: | + dist/* + man/pyee.1 diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 1b0f0fb..b81157f 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -175,31 +175,40 @@ I try to use git tags to tag versions - there's a just task: just tag ``` -### Build and Publish - -To publish the package, run: +### Push the Tag to GitHub ```bash -just publish +git push origin main --tags ``` -This should automatically build the package and upload with twine. However, -you can also build the package manually with `just build`, or upload the -existing build with `just upload`. - -## Push the Tag to GitHub +### Check on GitHub Actions -```bash -git push origin main --tags -``` +This should trigger a GitHub Action which publishes to PyPI and creates a +GitHub Release. Go to GitHub and make sure it worked. -## Check on RTD +### Check on RTD RTD should build automatically but I find there's a delay so I like to kick it off manually. Log into [RTD](https://readthedocs.org), log in, then go to [the pyee project page](https://readthedocs.org/projects/pyee/) and build latest and stable. -## (Optional) Announce on Twitter + +### (Optional) Announce on Twitter It's not official, but I like to announce the release on Twitter. + + +### (Optional) Build and Publish Manually + +If you want to publish the package manually, run: + +```bash +just publish +``` + +This should automatically build the package and upload with twine. However, +you can also build the package manually with `just build`, or upload the +existing build with `just upload`. + + diff --git a/justfile b/justfile index 2667b31..cdf25c4 100644 --- a/justfile +++ b/justfile @@ -146,7 +146,7 @@ _clean-build: # Tag the release in git tag: - . ./venv/bin/activate && git tag -a "$(python3 -c 'import toml; print(toml.load(open("pyproject.toml", "r"))["project"]["version"])')" -m "Release $(python3 -c 'import toml; print(toml.load(open("pyproject.toml", "r"))["project"]["version"])')" + . ./venv/bin/activate && git tag -a "v$(python3 -c 'import toml; print(toml.load(open("pyproject.toml", "r"))["project"]["version"])')" -m "Release $(python3 -c 'import toml; print(toml.load(open("pyproject.toml", "r"))["project"]["version"])')" # Upload built packages upload: diff --git a/pyproject.toml b/pyproject.toml index 4aed352..4db629c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,6 +35,7 @@ dependencies = [ [project.optional-dependencies] dev = [ + "build", "flake8", "flake8-black", "pytest",