Skip to content

Commit

Permalink
😇 Revamp CD workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
agriyakhetarpal committed Mar 23, 2024
1 parent f2fde08 commit 3b07096
Showing 1 changed file with 61 additions and 114 deletions.
175 changes: 61 additions & 114 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,20 @@ jobs:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v4
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0

- name: Set up Python 3.12
uses: actions/setup-python@v5
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: 3.12

- name: Install dependencies
run: |
python -m pip install build
- name: Build source distribution
run: |
python -m build --sdist --outdir dist/
pipx run build --sdist --outdir dist/
- uses: actions/upload-artifact@v4
- uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: source_distribution
path: dist
Expand All @@ -49,59 +45,53 @@ jobs:
name: Windows wheels (amd64)
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.12

- name: Set up Go toolchain
uses: actions/setup-go@v5
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: '1.22.1'
cache: false

- name: Install MinGW compiler(s)
run: choco install mingw

- uses: pypa/cibuildwheel@v2.17.0
- uses: pypa/cibuildwheel@8d945475ac4b1aac4ae08b2fd27db9917158b6ce # v2.17.0
with:
package-dir: .
output-dir: wheelhouse
env:
CIBW_BUILD: "cp312-*"
CIBW_ARCHS_WINDOWS: AMD64
CIBW_TEST_COMMAND: >
hugo version
hugo env --logLevel debug
- name: Upload wheels
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: windows_wheels
name: wheels_windows_amd64
path: ./wheelhouse/*.whl
if-no-files-found: error

linux_amd64_wheels:
name: Linux wheels (amd64)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: 3.8

- uses: pypa/cibuildwheel@v2.17.0
- uses: pypa/cibuildwheel@8d945475ac4b1aac4ae08b2fd27db9917158b6ce # v2.17.0
with:
package-dir: .
output-dir: wheelhouse
env:
CIBW_BUILD: "cp312-*"
CIBW_ARCHS_LINUX: x86_64
CIBW_BEFORE_ALL_LINUX: bash scripts/ci/tools/linux/install_go.sh
CIBW_ENVIRONMENT_LINUX: PATH=$PATH:$HOME/go_installed/go/bin
Expand All @@ -111,35 +101,32 @@ jobs:
hugo env --logLevel debug
- name: Upload wheels
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: linux_amd64_wheels
name: wheels_linux_amd64
path: ./wheelhouse/*.whl
if-no-files-found: error

linux_aarch64_wheels:
name: Linux wheels (aarch64)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: 3.8

- name: Set up QEMU for emulation
uses: docker/setup-qemu-action@v3
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0
with:
platforms: all

- uses: pypa/cibuildwheel@v2.17.0
- uses: pypa/cibuildwheel@8d945475ac4b1aac4ae08b2fd27db9917158b6ce # v2.17.0
with:
package-dir: .
output-dir: wheelhouse
env:
CIBW_BUILD: "cp312-*"
CIBW_ARCHS_LINUX: aarch64
CIBW_BEFORE_ALL_LINUX: bash scripts/ci/tools/linux/install_go.sh
CIBW_ENVIRONMENT_LINUX: PATH=$PATH:$HOME/go_installed/go/bin
Expand All @@ -149,9 +136,9 @@ jobs:
hugo env --logLevel debug
- name: Upload wheels
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: linux_aarch64_wheels
name: wheels_linux_aarch64
path: ./wheelhouse/*.whl
if-no-files-found: error

Expand All @@ -160,15 +147,15 @@ jobs:
runs-on: ubuntu-latest
needs: [linux_amd64_wheels, linux_aarch64_wheels]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0

- name: Download Linux wheels for both architectures
uses: actions/download-artifact@v4
uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 #v4.1.4

- name: Set up Python
uses: actions/setup-python@v5
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: 3.12

Expand All @@ -183,148 +170,108 @@ jobs:
python scripts/ci/tools/linux/repair_wheels.py ./wheelhouse_aarch64 ./repaired_linux_wheels
- name: Upload repaired Linux wheels
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: repaired_linux_wheels
path: ./repaired_linux_wheels/*.whl
if-no-files-found: error

macos_arm64_cp38_hotfix:
name: macOS wheels (arm64) with Python 3.8
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9

- name: Set up Go toolchain
uses: actions/setup-go@v5
with:
go-version: '1.22.1'
cache: false
check-latest: true

- uses: pypa/cibuildwheel@v2.17.0
with:
package-dir: .
output-dir: wheelhouse
env:
# Cross-compile for arm64 on macOS x86_64 with Python 3.8 for now
# See https://github.com/pypa/cibuildwheel/issues/1278
GOARCH: arm64
CIBW_ARCHS_MACOS: arm64
CIBW_PROJECT_REQUIRES_PYTHON: ">=3.8,<3.9"
CIBW_REPAIR_WHEEL_COMMAND_MACOS: ''

- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: macos_arm64_cp38_hotfix
path: ./wheelhouse/*.whl
if-no-files-found: error

macos_x86_64_wheels:
name: macOS wheels (x86_64)
runs-on: macos-latest
runs-on: macos-13
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.12

- name: Set up Go toolchain
uses: actions/setup-go@v5
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: '1.22.1'
cache: false
check-latest: true

- uses: pypa/cibuildwheel@v2.17.0
- uses: pypa/cibuildwheel@8d945475ac4b1aac4ae08b2fd27db9917158b6ce # v2.17.0
with:
package-dir: .
output-dir: wheelhouse
env:
CIBW_ARCHS_MACOS: x86_64
CIBW_BUILD: "cp312-*"
CIBW_REPAIR_WHEEL_COMMAND_MACOS: ''
CIBW_TEST_COMMAND: >
hugo version
hugo env --logLevel debug
- name: Upload wheels
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: macos_x86_64_wheels
name: wheels_macos_x86_64
path: ./wheelhouse/*.whl
if-no-files-found: error

macos_arm64_wheels:
name: macOS wheels (arm64)
runs-on: macos-14
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: 3.12

- name: Set up Go toolchain
uses: actions/setup-go@v5
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: '1.22.1'
cache: false
check-latest: true

- uses: pypa/cibuildwheel@v2.17.0
- uses: pypa/cibuildwheel@8d945475ac4b1aac4ae08b2fd27db9917158b6ce # v2.17.0
with:
package-dir: .
output-dir: wheelhouse
env:
CIBW_PROJECT_REQUIRES_PYTHON: ">=3.9"
CIBW_BUILD: "cp312-*"
CIBW_ARCHS_MACOS: arm64
CIBW_REPAIR_WHEEL_COMMAND_MACOS: ''
CIBW_TEST_COMMAND: >
hugo version
hugo env --logLevel debug
- name: Upload wheels
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: macos_arm64_wheels
name: wheels_macos_arm64
path: ./wheelhouse/*.whl
if-no-files-found: error

publish:
needs: [sdist, windows_wheels, repair_linux_wheels, macos_arm64_cp38_hotfix, macos_x86_64_wheels, macos_arm64_wheels]
needs: [sdist, windows_wheels, repair_linux_wheels, macos_x86_64_wheels, macos_arm64_wheels]
name: Publish to PyPI or TestPyPI
environment: release
permissions:
id-token: write
contents: write
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'published'
# if: github.event_name == 'release' && github.event.action == 'published'

steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
- name: Download all wheels
uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 #v4.1.4
with:
pattern: wheels_*
path: upload/
merge-multiple: true

- name: Move all artifacts to upload directory
run: |
mkdir upload
mv source_distribution/* windows_wheels/* repaired_linux_wheels/* macos_arm64_cp38_hotfix/* macos_x86_64_wheels/* macos_arm64_wheels/* upload/
- name: Download SDist
uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 #v4.1.4
with:
name: source_distribution
path: upload/
merge-multiple: true

- uses: pypa/gh-action-pypi-publish@release/v1
- uses: pypa/gh-action-pypi-publish@release/81e9d935c883d0b210363ab89cf05f3894778450 # v1.8.14
if: github.event_name == 'release' && github.event.action == 'published'
with:
# Remember to tell (test-)pypi about this repo before publishing
Expand All @@ -333,7 +280,7 @@ jobs:
packages-dir: upload

- name: Publish to GitHub Releases
uses: softprops/action-gh-release@v2.0.4
uses: softprops/action-gh-release@9d7c94cfd0a1f3ed45544c887983e9fa900f0564 # v2.0.4
if: github.event_name == 'release' && github.event.action == 'published'
with:
files: upload/*

0 comments on commit 3b07096

Please sign in to comment.