Update #256
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 Wheels | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- '**' | |
release: | |
types: | |
- created | |
- published | |
jobs: | |
build_wheels: | |
name: Build wheels on ${{ matrix.os }} | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-latest, macos-latest, windows-latest] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- uses: actions/setup-python@v2 | |
- name: Install cibuildwheel | |
run: python -m pip install cibuildwheel | |
- name: Build wheels | |
run: python -m cibuildwheel --output-dir wheelhouse | |
#- name: Prefix wheels with branch name | |
# if: startsWith(github.ref, 'refs/heads/') | |
# run: | | |
# branchName=${GITHUB_REF/refs\/heads\//} | |
# for file in wheelhouse/*.whl; do | |
# newName="${branchName}-$(basename $file)" | |
# mv "$file" "wheelhouse/$newName" | |
# done | |
# shell: bash | |
- uses: actions/upload-artifact@v2 | |
with: | |
name: wheels | |
path: wheelhouse/*.whl | |
publish_wheels_to_gh_pages: | |
name: Publish wheels to GitHub Pages | |
runs-on: ubuntu-latest | |
needs: build_wheels | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Download artifacts | |
uses: actions/download-artifact@v2 | |
with: | |
name: wheels | |
path: wheelhouse | |
- name: Checkout gh-pages branch | |
uses: actions/checkout@v2 | |
with: | |
ref: 'gh-pages' | |
path: 'gh-pages' | |
- name: Copy wheels to gh-pages branch | |
run: | | |
mkdir -p gh-pages/wheels | |
cp wheelhouse/*.whl gh-pages/wheels/ | |
- name: Create index.html for wheels directory | |
run: | | |
cd gh-pages/wheels | |
echo "<!DOCTYPE html>" > index.html | |
echo "<html>" >> index.html | |
echo "<head><title>Index of wheels</title></head>" >> index.html | |
echo "<body>" >> index.html | |
echo "<h1>Index of wheels</h1>" >> index.html | |
echo "<ul>" >> index.html | |
for wheel in *.whl; do | |
echo "<li><a href=\"$wheel\">$wheel</a></li>" >> index.html | |
done | |
echo "</ul>" >> index.html | |
echo "</body>" >> index.html | |
echo "</html>" >> index.html | |
- name: Commit and push wheels to gh-pages branch | |
run: | | |
cd gh-pages | |
git config user.name "GitHub Actions" | |
git config user.email "actions@github.com" | |
git add wheels/*.whl wheels/index.html | |
git commit -m "Upload wheels to GitHub Pages and update index.html" | |
git push | |
publish_wheels_to_pypi: | |
name: Publish wheels to PyPI | |
needs: build_wheels | |
runs-on: ubuntu-latest | |
if: github.event_name == 'release' && github.event.action == 'created' | |
steps: | |
- name: Download artifacts | |
uses: actions/download-artifact@v2 | |
with: | |
name: wheels | |
path: wheelhouse | |
- name: Publish to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
password: ${{ secrets.PYPI_API_TOKEN }} | |
packages_dir: wheelhouse | |
publish_wheels_to_release_page: | |
name: Publish wheels to Release Page | |
needs: build_wheels | |
runs-on: ubuntu-latest | |
if: github.event_name == 'release' && github.event.action == 'created' | |
steps: | |
- name: Download artifacts | |
uses: actions/download-artifact@v2 | |
with: | |
name: wheels | |
path: wheelhouse | |
- name: Get release info | |
uses: actions/github-script@v5 | |
id: get_release_info | |
with: | |
script: | | |
const { upload_url } = await github.rest.repos.getReleaseByTag({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
tag: context.payload.release.tag_name, | |
}); | |
return { upload_url: upload_url }; | |
- name: Print upload URL | |
run: echo "Upload URL is ${{ steps.get_release_info.outputs.upload_url }}" | |
- name: Upload wheels to release assets | |
uses: shogo82148/actions-upload-release-asset@v1 | |
with: | |
upload_url: ${{ steps.get_release_info.outputs.upload_url }} | |
asset_path: wheelhouse/*.whl |