Build wheels on macos and windows but upload from only ubuntu #14
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build loadgen wheels and release them into PYPI | |
on: | |
release: | |
types: [published] | |
push: | |
branches: | |
- master | |
- loadgen-dev | |
paths: | |
- loadgen/** | |
jobs: | |
build_wheels: | |
name: Build wheels on ${{ matrix.os }} | |
runs-on: ${{ matrix.os }} | |
environment: release | |
permissions: | |
# IMPORTANT: this permission is mandatory for trusted publishing | |
id-token: write | |
contents: write | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-latest, windows-latest, macOS-latest] | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-python@v3 | |
# Step 3: Check if VERSION.txt file has changed in this push | |
- name: Check if VERSION.txt file has changed | |
id: version_changed | |
if: runner.os == 'Linux' | |
run: | | |
if git diff --name-only HEAD~1 | grep -q "VERSION.txt"; then | |
echo "VERSION.txt file has been modified" | |
echo "::set-output name=version_changed::true" | |
new_version=$(cat VERSION.txt) | |
else | |
echo "VERSION file has NOT been modified" | |
echo "::set-output name=version_changed::false" | |
fi | |
echo "::set-output name=new_version::$new_version" | |
# Step 4: Increment version if VERSION was not changed | |
- name: Increment version if necessary | |
id: do_version_increment | |
if: runner.os == 'Linux' && steps.version_changed.outputs.version_changed == 'false' | |
run: | | |
cd loadgen | |
# Check if VERSION file exists, else initialize it | |
if [ ! -f VERSION.txt ]; then | |
echo "0.0.0" > VERSION.txt | |
fi | |
version=$(cat VERSION.txt) | |
IFS='.' read -r major minor patch <<< "$version" | |
patch=$((patch + 1)) | |
new_version="$major.$minor.$patch" | |
echo $new_version > VERSION.txt | |
echo "New version: $new_version" | |
echo "::set-output name=new_version::$new_version" | |
# Step 5: Commit the updated version to the repository | |
- name: Commit updated version | |
if: steps.version_changed.outputs.version_changed == 'false' && runner.os == 'Linux' | |
run: | | |
cd loadgen | |
git config --global user.name "${{ github.actor }}" | |
git config --global user.email "${{ github.actor }}@users.noreply.github.com" | |
git add VERSION.txt | |
git commit -m "Increment version to ${{ steps.do_version_increment.outputs.new_version }}" | |
git push | |
- name: Install requirements | |
run: python -m pip install cibuildwheel twine | |
- name: Build wheels | |
run: python -m cibuildwheel loadgen/ --output-dir wheels | |
# Save wheels as artifacts | |
- name: Upload built wheels | |
uses: actions/upload-artifact@v3 | |
with: | |
name: all-wheels | |
path: wheels | |
publish_wheels: | |
needs: build_wheels # Wait for the build_wheels job to complete | |
runs-on: ubuntu-latest # Only run this job on Linux | |
steps: | |
- uses: actions/checkout@v3 | |
# Download the built wheels from all platforms | |
- name: Download all wheels | |
uses: actions/download-artifact@v3 | |
with: | |
name: all-wheels | |
- name: Publish | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
verify-metadata: true | |
skip-existing: true | |
packages-dir: wheels | |
repository-url: https://upload.pypi.org/legacy/ | |
verbose: true |