Skip to content

Commit

Permalink
Add pypi package build in Github Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
dunkmann00 committed Apr 12, 2024
1 parent 6526882 commit c3297b7
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 13 deletions.
57 changes: 52 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,58 @@ on:

env:
PYTHONUNBUFFERED: 1
PYTHON_VERSION: "3.11"

jobs:
notifications-build:
uses: ./.github/workflows/notifications.yml

package-build:
name: Build PyPI Package
needs: notifications-build
runs-on: ubuntu-22.04
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Setup Poetry
uses: ./.github/actions/setup-poetry
- name: Install Drive Backup package & dependencies
run: poetry install
- name: Get notification apps
id: download-notifications
uses: actions/download-artifact@v4
with:
path: ${{ github.workspace }}/notifications-artifacts
pattern: ${{ needs.notifications-build.outputs.artifact-project-name }}*
merge-multiple: true
- name: Unzip & move notifications apps
env:
ARTIFACTS_PATH: ${{ steps.download-notifications.outputs.download-path }}
MACOS_ARTIFACT_NAME: ${{ needs.notifications-build.outputs.macos-artifact-name }}
MACOS_BUILD_PATH: ${{ needs.notifications-build.outputs.macos-build-path }}
WINDOWS_ARTIFACT_NAME: ${{ needs.notifications-build.outputs.windows-artifact-name }}
WINDOWS_BUILD_PATH: ${{ needs.notifications-build.outputs.windows-build-path }}
run: |
# macOS Notifications App
unzip "$ARTIFACTS_PATH/$MACOS_ARTIFACT_NAME.zip" -d "$MACOS_BUILD_PATH"
# Windows Notifications App
unzip "$ARTIFACTS_PATH/$WINDOWS_ARTIFACT_NAME.zip" -d "$WINDOWS_BUILD_PATH"
- name: Build package sdist & wheel
run: poetry build
- name: Upload package sdist & wheel
uses: actions/upload-artifact@v4
with:
name: pypi-package-build
path: ./dist

binary-build:
name: Build ${{ matrix.os }} App Binary
needs: notifications-build
Expand All @@ -40,7 +87,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: ${{ env.PYTHON_VERSION }}
- name: Setup Poetry
uses: ./.github/actions/setup-poetry
- name: Setup Keychain (macOS)
Expand All @@ -61,7 +108,7 @@ jobs:
- name: Unzip notification app (macOS & Windows)
if: runner.os == 'macOS' || runner.os == 'Windows'
env:
NOTIFICATION_NAME: ${{ needs.notifications-build.outputs.project-name }}
NOTIFICATION_NAME: ${{ matrix.notifications.artifact-name }}
NOTFICATION_BUILD: ${{ matrix.notifications.build-path }}
run: python -c "import shutil; shutil.unpack_archive('$NOTFICATION_BUILD/$NOTIFICATION_NAME.zip', '$NOTFICATION_BUILD')"
- name: Build app binary
Expand All @@ -76,7 +123,7 @@ jobs:
MACOS_NOTARIZATION_PWD: ${{ secrets.PROD_MACOS_NOTARIZATION_PWD }}
run: |
echo "Create Zip Archive"
ZIP_PATH=$(poetry run python app-build.py archive --format zip)
ZIP_PATH="$(poetry run python app-build.py archive --format zip)"
# Here we send the notarization request to Apple's Notarization service, waiting for the result.
# This typically takes a few seconds inside a CI environment, but it might take more depending on the App
Expand Down Expand Up @@ -118,11 +165,11 @@ jobs:
- name: Archive app
run: |
# Build the archive and store the path to it
ARCHIVE_PATH=$(poetry run python app-build.py archive --name $ARCHIVE_NAME)
ARCHIVE_PATH="$(poetry run python app-build.py archive --archive-name "$ARCHIVE_NAME")"
# Store the archive path as an environment variable
echo "ARCHIVE_PATH=$ARCHIVE_PATH" >> "$GITHUB_ENV"
- name: Upload archive artifact
- name: Upload binary archive
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARCHIVE_NAME }}
Expand Down
22 changes: 14 additions & 8 deletions .github/workflows/notifications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ on:
project-name:
description: Name of the notification apps (they both use the same name).
value: ${{ jobs.mac-notifications.outputs.project-name }}
artifact-project-name:
description: Artifact name of the notification apps without the platform.
value: ${{ jobs.mac-notifications.outputs.artifact-project-name }}
macos-build-path:
description: Path to the macOS notification app build directory.
value: ${{ jobs.mac-notifications.outputs.build-path }}
Expand Down Expand Up @@ -42,6 +45,7 @@ jobs:
NOTIFICATION_PROJECT_PATH: ${{ github.workspace }}/src/drive_backup/core/notifications/mac
outputs:
project-name: ${{ steps.setup-variables.outputs.PROJECT_NAME }}
artifact-project-name: ${{ steps.setup-variables.outputs.ARTIFACT_PROJECT_NAME }}
build-path: ${{ steps.setup-variables.outputs.BUILD_PATH }}
artifact-name: ${{ steps.setup-variables.outputs.ARTIFACT_NAME }}
steps:
Expand All @@ -51,16 +55,18 @@ jobs:
- name: Setup Env Variables
id: setup-variables
run: |
ARTIFACT_PROJECT_NAME="$(echo "$PROJECT_NAME" | tr " " _)"
ARTIFACT_NAME="$ARTIFACT_PROJECT_NAME-macos"
echo "ARTIFACT_NAME=$ARTIFACT_NAME" >> "$GITHUB_ENV"
BUILD_PATH="$NOTIFICATION_PROJECT_PATH/build"
echo "BUILD_PATH=$BUILD_PATH" >> "$GITHUB_ENV"
echo "APP_PATH=$BUILD_PATH/$PROJECT_NAME.app" >> "$GITHUB_ENV"
echo "ZIP_PATH=$BUILD_PATH/$PROJECT_NAME.zip" >> "$GITHUB_ENV"
ARTIFACT_NAME="$(echo "$PROJECT_NAME" | tr " " _)-macos"
echo "ARTIFACT_NAME=$ARTIFACT_NAME" >> "$GITHUB_ENV"
echo "ZIP_PATH=$BUILD_PATH/$ARTIFACT_NAME.zip" >> "$GITHUB_ENV"
echo "PROJECT_NAME=$PROJECT_NAME" >> "$GITHUB_OUTPUT"
echo "BUILD_PATH=$BUILD_PATH" >> "$GITHUB_OUTPUT"
echo "ARTIFACT_PROJECT_NAME=$ARTIFACT_PROJECT_NAME" >> "$GITHUB_OUTPUT"
echo "ARTIFACT_NAME=$ARTIFACT_NAME" >> "$GITHUB_OUTPUT"
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -138,13 +144,13 @@ jobs:
- name: Setup Env Variables
id: setup-variables
run: |
$ARTIFACT_NAME=$env:PROJECT_NAME.Replace(" ","_") + "-windows"
echo "ARTIFACT_NAME=$ARTIFACT_NAME" >> "$env:GITHUB_ENV"
$BUILD_PATH="$env:NOTIFICATION_PROJECT_PATH\build"
echo "BUILD_PATH=$BUILD_PATH" >> "$env:GITHUB_ENV"
echo "EXE_PATH=$BUILD_PATH\$env:PROJECT_NAME.exe" >> "$env:GITHUB_ENV"
echo "ZIP_PATH=$BUILD_PATH\$env:PROJECT_NAME.zip" >> "$env:GITHUB_ENV"
$ARTIFACT_NAME=$env:PROJECT_NAME.Replace(" ","_") + "-windows"
echo "ARTIFACT_NAME=$ARTIFACT_NAME" >> "$env:GITHUB_ENV"
echo "ZIP_PATH=$BUILD_PATH\$env:ARTIFACT_NAME.zip" >> "$env:GITHUB_ENV"
echo "BUILD_PATH=$BUILD_PATH" >> "$env:GITHUB_OUTPUT"
echo "ARTIFACT_NAME=$ARTIFACT_NAME" >> "$env:GITHUB_OUTPUT"
Expand Down

0 comments on commit c3297b7

Please sign in to comment.