From 13c2444d77fb6a518d91538a178b2119c4d5202d Mon Sep 17 00:00:00 2001 From: gawor Date: Thu, 11 Apr 2024 17:11:21 +0200 Subject: [PATCH] missing release wheel CI from the stack tree --- .github/workflows/release_wheel.yml | 106 ++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 .github/workflows/release_wheel.yml diff --git a/.github/workflows/release_wheel.yml b/.github/workflows/release_wheel.yml new file mode 100644 index 0000000..9733270 --- /dev/null +++ b/.github/workflows/release_wheel.yml @@ -0,0 +1,106 @@ +name: Build and release wheel + +on: + push: + branches: + - "master" + - "wheel" + tags: + - '[0-9]+.[0-9]+.[0-9]+' + - '[0-9]+.[0-9]+.[0-9]+rc[x0-9]+' + - '[0-9]+.[0-9]+.[0-9]+-rc[x0-9]+' + pull_request: + release: + types: [published] + workflow_dispatch: +defaults: + run: + shell: bash + +jobs: + prepare: + name: "Prepare" + runs-on: ubuntu-22.04 + outputs: + version: ${{ steps.get_version.outputs.VERSION }} + create_release: ${{ steps.check_release.outputs.CREATE_RELEASE }} + steps: + - name: Get the version + id: get_version + run: echo "VERSION=${GITHUB_REF##*/}" >> $GITHUB_OUTPUT + - name: Check create release for tag + if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') + id: check_release + run: | + URL="https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.get_version.outputs.VERSION }}" + StatusCode=$(curl -o -I -L -s -w "%{http_code}" -X GET -G $URL) + if [ "$StatusCode" == 200 ]; then + echo "Release exists" + echo "CREATE_RELEASE=false" >> $GITHUB_OUTPUT + else + echo "Release does not exist" + echo "CREATE_RELEASE=true" >> $GITHUB_OUTPUT + fi + build_wheel: + needs: [prepare] + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Build wheel + run: | + cd .. + docker run -v ./DOGapp:/src -v ./whl:/whl registry.gitlab.com/clarin-eric/docker-alpine-wheeler:0.0.1-a10 + - name: 'Tar wheeler output and changelog' + run: tar -cvf workspace.tar ../whl/*.whl ./CHANGELOG.md + - uses: actions/upload-artifact@v4 + with: + name: workspace + path: workspace.tar + retention-days: 1 + release: + name: "Release" + needs: [prepare, build_wheel] + # Run job for github releases and tag pushes (without github release) + if: github.event_name == 'release' || needs.prepare.outputs.create_release == 'true' + runs-on: ubuntu-22.04 + permissions: + contents: write + steps: + - name: 'Download workspace' + uses: actions/download-artifact@v4 + with: + name: workspace + - name: 'Untar workspace' + run: tar -xvf workspace.tar + # For github releases -> upload release package to existing release + # For tag pushes without github release -> create a github release with release package + - name: Create release + if: needs.prepare.outputs.create_release == 'true' + id: create_release + uses: ncipollo/release-action@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag: ${{ needs.prepare.outputs.version }} + name: ${{ needs.prepare.outputs.version }} + draft: false + prerelease: true + bodyFile: CHANGELOG.md + - name: Add to existing release + uses: shogo82148/actions-upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + # Pseudo-ternary expression: get "upload_url" from the release created above, or from github "release" event when release is pre-created + upload_url: ${{ needs.prepare.outputs.create_release == 'true' && steps.create_release.outputs.upload_url || github.event.release.upload_url }} + asset_path: ./whl/*.whl + asset_content_type: application/gzip + - uses: eregon/publish-release@v1 + if: needs.prepare.outputs.create_release == 'true' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + release_id: ${{ steps.create_release.outputs.id }}