Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jgosmann committed Feb 17, 2024
2 parents 644d86a + 36defc5 commit d13c20a
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 1 deletion.
21 changes: 21 additions & 0 deletions .github/actions/check-prerelease/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Checks whether a version is a prerelease
description: Checks whether a version is prerelease according to PEP440.
inputs:
version:
description: Version number to check.
required: true
outputs:
prerelease:
description: Whether the version number is a prerelease.
value: ${{ steps.check-prerelease.outputs.PRERELEASE }}
runs:
using: composite
steps:
- name: Install packaging
run: pip install packaging
shell: bash

- name: Check if prerelease
id: check-prerelease
run: ./.github/actions/check-prerelease/check_prerelease.py ${{ inputs.version }} >> "$GITHUB_OUTPUT"
shell: bash
17 changes: 17 additions & 0 deletions .github/actions/check-prerelease/check_prerelease.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python3

import argparse

from packaging.version import parse as parse_version

if __name__ == "__main__":
arg_parser = argparse.ArgumentParser(
description="Check whether a version is a prerelease according to PEP440."
)
arg_parser.add_argument("version")
args = arg_parser.parse_args()

if parse_version(args.version).is_prerelease:
print("PRERELEASE=true")
else:
print("PRERELEASE=false")
21 changes: 21 additions & 0 deletions .github/actions/get-latest-release/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Get latest release
description: Gets the latest (non-prerelease) version of a PyPI package.
inputs:
package:
description: Name of the the package.
required: true
outputs:
latest_version:
description: Latest version of the package.
value: ${{ steps.get-latest.outputs.VERSION }}
runs:
using: composite
steps:
- name: Install packaging
run: pip install packaging requests
shell: bash

- name: Get latest version
id: get-latest
run: ./.github/actions/get-latest-release/get_latest_release.py ${{ inputs.package }} >> "$GITHUB_OUTPUT"
shell: bash
24 changes: 24 additions & 0 deletions .github/actions/get-latest-release/get_latest_release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python3

import argparse

import requests
from packaging.version import parse as parse_version

if __name__ == "__main__":
arg_parser = argparse.ArgumentParser(
description="Get the latest non-prerelease version of a package according to PEP440."
)
arg_parser.add_argument("package")
args = arg_parser.parse_args()

r = requests.get(
f"https://pypi.org/simple/{args.package}",
headers={"Accept": "application/vnd.pypi.simple.v1+json"},
timeout=30,
)
r.raise_for_status()
versions = [parse_version(v) for v in r.json().get("versions", [])]
latest = max(v for v in versions if not v.is_prerelease)
if latest:
print(f"VERSION={latest}")
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,18 @@ jobs:
with:
args: --standalone --wrap none -f rst -t gfm --output=release-body.md release-body.rst

- name: Check if prerelease
id: check-prerelease
uses: ./.github/actions/check-prerelease
with:
version: ${{ steps.version.outputs.version }}

- name: Create GitHub release
uses: softprops/action-gh-release@v1
with:
body_path: release-body.md
tag_name: v${{ steps.version.outputs.version }}
prerelease: ${{ steps.check-prerelease.outputs.prerelease }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
28 changes: 27 additions & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,40 @@ jobs:
with:
images: ${{ env.IMAGE_NAME }}

- name: Check if prerelease
id: check-prerelease
uses: ./.github/actions/check-prerelease
with:
version: ${{ steps.version.outputs.version }}

- name: Get latest release
id: latest-version
uses: ./.github/actions/get-latest-release
with:
package: dmarc-metrics-exporter

- name: Set tags
id: set-tags
shell: bash
run: |
{
echo 'TAGS<<EOF'
echo ${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}
[ ${{ steps.version.outputs.version }} = ${{ steps.latest-version.outputs.latest_version }} ] \
&& [ ${{ steps.check-prerelease }} != true ] \
&& echo ${{ env.IMAGE_NAME }}:latest
echo EOF
} >> "$GITHUB_OUTPUT"
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}
tags: ${{ steps.set-tags.outputs.TAGS }}
platforms: linux/amd64,linux/arm64
labels: ${{ steps.meta.outputs.labels }}
build-args: "version=${{ steps.version.outputs.version }}"

0 comments on commit d13c20a

Please sign in to comment.