Skip to content

Commit

Permalink
support Python 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed Oct 9, 2023
1 parent 7bcd88c commit 4b7b0b5
Show file tree
Hide file tree
Showing 7 changed files with 503 additions and 403 deletions.
3 changes: 1 addition & 2 deletions .actrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
-W .github/workflows/build.yml
-j build
--matrix os:ubuntu-latest
--matrix PYTHON_VERSION:3.11

--matrix PYTHON_VERSION:3.12
48 changes: 18 additions & 30 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ jobs:
PYTHON_VERSION: "3.10"
PUBLISH_RELEASE: false
- os: ubuntu-latest
PYTHON_VERSION: "3.11"
PYTHON_VERSION: "3.12"
PUBLISH_RELEASE: true
- os: windows-latest
PYTHON_VERSION: "3.11"
PYTHON_VERSION: "3.12"
PUBLISH_RELEASE: true

runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -85,9 +85,7 @@ jobs:
python -m pip install --upgrade pip
# pin packaging to 21.3 for now to prevent: packaging.specifiers.InvalidSpecifier: Invalid specifier: '>=3.4.*'
# see https://github.com/pdm-project/pdm/issues/1556
pip install --upgrade pdm packaging==21.3
pip install --upgrade pdm
pdm install -v
Expand Down Expand Up @@ -205,7 +203,7 @@ jobs:

steps:
- name: Git checkout
# only required by "hub release create" to prevent "fatal: Not a git repository"
# only required by "gh release create" to prevent "fatal: Not a git repository"
uses: actions/checkout@v4 #https://github.com/actions/checkout

- name: Generate GitHub access token
Expand All @@ -227,42 +225,32 @@ jobs:
uses: actions/download-artifact@v3

- name: "Delete previous 'latest' release"
run: |
set -eu
api_base_url="$GITHUB_API_URL/repos/$GITHUB_REPOSITORY"
# delete 'latest' github release
release_id=$(curl -fsL -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/$GITHUB_REPOSITORY/releases | jq -r '.[] | select(.name == "latest") | .id')
if [[ -n $release_id ]]; then
echo "Deleting release [$api_base_url/releases/$release_id]..."
curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -fsSL -X DELETE "$api_base_url/releases/$release_id"
fi
# delete 'latest' git tag
tag_url="$api_base_url/git/refs/tags/latest"
if curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -fsLo /dev/null --head "$tag_url"; then
echo "Deleting tag [$tag_url]..."
curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -fsSL -X DELETE "$tag_url"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_NAME: latest
# https://cli.github.com/manual/gh_release_delete
run: gh release delete "$RELEASE_NAME" --yes --cleanup-tag || true

- name: "Create 'latest' release"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_NAME: latest
run: |
set -eux
mv artifacts-macos-latest/kleinanzeigen-bot kleinanzeigen-bot-darwin-amd64
mv artifacts-ubuntu-latest/kleinanzeigen-bot kleinanzeigen-bot-linux-amd64
mv artifacts-windows-latest/kleinanzeigen-bot.exe kleinanzeigen-bot-windows-amd64.exe
# https://hub.github.com/hub-release.1.html
hub release create "latest" \
# https://cli.github.com/manual/gh_release_create
gh release create "$RELEASE_NAME" \
--latest \
--prerelease \
--message "latest" \
--attach "kleinanzeigen-bot-darwin-amd64" \
--attach "kleinanzeigen-bot-linux-amd64" \
--attach "kleinanzeigen-bot-windows-amd64.exe"
--target "${{ github.sha }}" \
--notes "$RELEASE_NAME" \
kleinanzeigen-bot-darwin-amd64 \
kleinanzeigen-bot-linux-amd64 \
kleinanzeigen-bot-windows-amd64.exe
- name: "Delete intermediate build artifacts"
uses: geekyeggo/delete-artifact@v2 # https://github.com/GeekyEggo/delete-artifact/
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ defaults:
shell: bash

env:
PYTHON_VERSION: "3.11"
PYTHON_VERSION: "3.11" # TODO don't upgrade to 3.12 yet, which results in "ModuleNotFoundError: No module named 'imp'"

jobs:
analyze:
name: Analyze
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/update-python-deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defaults:
shell: bash

env:
PYTHON_VERSION: "3.11"
PYTHON_VERSION: "3.12"

jobs:

Expand Down Expand Up @@ -68,7 +68,7 @@ jobs:
set -euo pipefail
exec 5>&1
updates=$(pdm update 2>&1 |tee /dev/fd/5)
updates=$(pdm update --update-all 2>&1 |tee /dev/fd/5)
if git diff --exit-code pdm.lock; then
echo "updates=" >> "$GITHUB_OUTPUT"
Expand Down
84 changes: 56 additions & 28 deletions docker/image/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#syntax=docker/dockerfile:1.4
# see https://docs.docker.com/build/dockerfile/frontend/#dockerfile-frontend
# see https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#syntax
# see https://docs.docker.com/engine/reference/builder/#syntax
#
# Copyright (C) 2022 Sebastian Thomschke and contributors
# SPDX-License-Identifier: AGPL-3.0-or-later
Expand All @@ -8,58 +12,76 @@
######################
FROM debian:stable-slim as runtime-base-image

LABEL maintainer="Sebastian Thomschke"

ARG DEBIAN_FRONTEND=noninteractive
ARG LC_ALL=C

RUN set -eu \
#
&& apt-get update -y \
&& echo "#################################################" \
&& echo "Install Chromium + Driver..." \
&& echo "#################################################" \
&& apt-get install --no-install-recommends -y chromium chromium-driver \
#
&& rm -rf \
SHELL ["/bin/bash", "-euo", "pipefail", "-c"]

RUN <<EOF

apt-get update

echo "#################################################"
echo "Install Chromium + Driver..."
echo "#################################################"
apt-get install --no-install-recommends -y chromium chromium-driver

apt-get clean autoclean
apt-get autoremove --purge -y
rm -rf \
/var/cache/{apt,debconf} \
/var/lib/apt/lists/* \
/var/log/{apt,alternatives.log,bootstrap.log,dpkg.log} \
/tmp/* /var/tmp/*

EOF

######################
# build image
######################

# https://hub.docker.com/_/python?tab=tags&name=3-slim
# https://hub.docker.com/_/python/tags?name=3-slim
FROM python:3-slim AS build-image

RUN apt-get update \
# install required libraries
&& apt-get install --no-install-recommends -y \
ARG DEBIAN_FRONTEND=noninteractive
ARG LC_ALL=C

SHELL ["/bin/bash", "-euo", "pipefail", "-c"]

RUN <<EOF

apt-get update

# install required libraries
apt-get install --no-install-recommends -y \
binutils `# required by pyinstaller` \
build-essential `# required by transitive dependency "wrapt"` \
git `# required by pdm to generate app version` \
#
# upgrade pip
&& python -m pip install --upgrade pip \
#
# install pdm
&& pip install pdm

# upgrade pip
python -m pip install --upgrade pip \

# install pdm
pip install pdm

EOF

ENV PATH="/opt/upx:${PATH}"

COPY kleinanzeigen_bot /opt/app/kleinanzeigen_bot
COPY .git /opt/app/.git
COPY README.md pdm.lock pyinstaller.spec pyproject.toml /opt/app/

RUN cd /opt/app \
&& ls -la . \
&& pdm install -v \
&& ls -la kleinanzeigen_bot \
&& pdm run compile \
&& ls -l dist
RUN <<EOF

cd /opt/app
ls -la .
pdm install -v
ls -la kleinanzeigen_bot
pdm run compile
ls -l dist

EOF

RUN /opt/app/dist/kleinanzeigen-bot --help

Expand All @@ -76,10 +98,16 @@ ARG GIT_COMMIT_DATE
ARG GIT_REPO_URL

LABEL \
maintainer="Sebastian Thomschke" \
org.label-schema.schema-version="1.0" \
org.label-schema.build-date=$BUILD_DATE \
org.label-schema.vcs-ref=$GIT_COMMIT_HASH \
org.label-schema.vcs-url=$GIT_REPO_URL
org.label-schema.vcs-url=$GIT_REPO_URL \
org.opencontainers.image.authors="Sebastian Thomschke" \
org.opencontainers.image.vendor="Sebastian Thomschke" \
org.opencontainers.image.licenses="AGPL-3.0" \
org.opencontainers.image.title="kleinanzeigen-bot" \
org.opencontainers.image.description="CLI application to ease publishing of ads to kleinanzeigen.de"

# https://stackoverflow.com/a/59812588/5116073
ENV PYTHONUNBUFFERED=1
Expand Down
Loading

0 comments on commit 4b7b0b5

Please sign in to comment.