ci: consolidate release into build.yml, fix Conan cache #98
This file contains hidden or 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 | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| tags: [ "v*" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| concurrency: | |
| group: build-${{ github.ref }} | |
| cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/') }} | |
| jobs: | |
| build_wheels: | |
| name: Build wheels on ${{ matrix.os }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| # macos-13 is an intel runner, macos-14 is apple silicon | |
| os: [ ubuntu-latest, windows-latest, macos-14 ] | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - name: Cache Conan packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: .conan2/p | |
| key: conan-${{ matrix.os }}-${{ hashFiles('conanfile.py', 'pyproject.toml') }} | |
| restore-keys: | | |
| conan-${{ matrix.os }}- | |
| - name: Build wheels | |
| uses: pypa/cibuildwheel@v4.1.0 | |
| env: | |
| CIBW_CONTAINER_ENGINE: "docker; create_args: --volume ${{ github.workspace }}/.conan2:/project/.conan2" | |
| - name: Reclaim Conan home ownership | |
| if: always() && runner.os == 'Linux' | |
| run: sudo chown -R "$(id -u):$(id -g)" .conan2 | |
| - uses: actions/upload-artifact@v7 | |
| with: | |
| name: dist-${{ matrix.os }} | |
| path: ./wheelhouse/*.whl | |
| make_sdist: | |
| name: Build sdist | |
| if: startsWith(github.ref, 'refs/tags/') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - name: Build sdist | |
| run: pipx run build --sdist | |
| - uses: actions/upload-artifact@v7 | |
| with: | |
| name: dist-sdist | |
| path: dist/*.tar.gz | |
| publish: | |
| name: Publish | |
| if: startsWith(github.ref, 'refs/tags/') && github.repository == 'EndstoneMC/dwarf2cpp' | |
| needs: [ build_wheels, make_sdist ] | |
| runs-on: ubuntu-latest | |
| environment: pypi | |
| permissions: | |
| id-token: write | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v7 | |
| with: | |
| fetch-depth: 0 | |
| - name: Download distributions | |
| uses: actions/download-artifact@v7 | |
| with: | |
| pattern: dist-* | |
| path: dist | |
| merge-multiple: true | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| packages-dir: dist | |
| - name: Extract release notes | |
| run: | | |
| VERSION="${GITHUB_REF_NAME#v}" | |
| BODY=$(sed -n "/^## \[$VERSION\]/,/^## \[/{/^## \[/d; p}" CHANGELOG.md) | |
| BODY=$(echo "$BODY" | sed '/./,$!d' | sed -e :a -e '/^\n*$/{$d;N;ba}') | |
| if [ -z "$BODY" ]; then | |
| echo "::error::No [$VERSION] section found in CHANGELOG.md" | |
| exit 1 | |
| fi | |
| printf '%s\n' "$BODY" > /tmp/release_body.md | |
| PREV_TAG=$(git tag --sort=-v:refname | sed -n '2p') | |
| if [ -n "$PREV_TAG" ]; then | |
| printf '\n**Full Changelog**: https://github.com/%s/compare/%s...%s\n' \ | |
| "${{ github.repository }}" "$PREV_TAG" "$GITHUB_REF_NAME" >> /tmp/release_body.md | |
| fi | |
| - name: Create GitHub Release | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: gh release create "$GITHUB_REF_NAME" --title "$GITHUB_REF_NAME" --notes-file /tmp/release_body.md dist/* |