|
| 1 | +name: Build and release |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - master |
| 6 | + - maintenance/* |
| 7 | + create: |
| 8 | + tags: |
| 9 | + - 'v[0-9]+.[0-9]+.[0-9]+*' |
| 10 | + |
| 11 | +defaults: |
| 12 | + run: |
| 13 | + shell: bash |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + name: Build and Release |
| 18 | + runs-on: ubuntu-latest |
| 19 | + env: |
| 20 | + PACKAGE_NAME: labscript-utils |
| 21 | + SCM_VERSION_SCHEME: release-branch-semver |
| 22 | + SCM_LOCAL_SCHEME: no-local-version |
| 23 | + if: github.repository == 'labscript-suite/labscript-utils' && (github.event_name != 'create' || github.event.ref_type != 'branch') |
| 24 | + steps: |
| 25 | + - name: Checkout |
| 26 | + uses: actions/checkout@v2 |
| 27 | + - name: Unshallow |
| 28 | + if: github.event.ref_type != 'tag' |
| 29 | + run: | |
| 30 | + git fetch --prune --unshallow |
| 31 | + git tag -d $(git tag --points-at HEAD) |
| 32 | + - name: Install Python |
| 33 | + uses: actions/setup-python@v2 |
| 34 | + with: |
| 35 | + python-version: 3.8 |
| 36 | + - name: Build Distributions |
| 37 | + run: | |
| 38 | + python -m pip install --upgrade pip setuptools wheel |
| 39 | + pip install -U git+https://github.com/pypa/setuptools_scm.git@8e6aa2b5fd42cb257c86e6dbe720eaee6d1e2c9b |
| 40 | + python setup.py sdist bdist_wheel |
| 41 | + SCM_VERSION=$(python setup.py --version) |
| 42 | + echo "::set-env name=SCM_VERSION::$SCM_VERSION" |
| 43 | + - name: Publish on TestPyPI |
| 44 | + if: github.event.ref_type == 'tag' || contains(env.SCM_VERSION, 'dev') |
| 45 | + uses: pypa/gh-action-pypi-publish@master |
| 46 | + with: |
| 47 | + user: __token__ |
| 48 | + password: ${{ secrets.testpypi }} |
| 49 | + repository_url: https://test.pypi.org/legacy/ |
| 50 | + - name: Get Version Number |
| 51 | + if: github.event.ref_type == 'tag' |
| 52 | + run: | |
| 53 | + VERSION="${GITHUB_REF/refs\/tags\/v/}" |
| 54 | + echo "::set-env name=VERSION::$VERSION" |
| 55 | + - name: Create GitHub Release |
| 56 | + if: github.event.ref_type == 'tag' |
| 57 | + id: create_release |
| 58 | + uses: actions/create-release@latest |
| 59 | + env: |
| 60 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 61 | + with: |
| 62 | + tag_name: ${{ github.event.ref }} |
| 63 | + release_name: ${{ env.PACKAGE_NAME }} ${{ env.VERSION }} |
| 64 | + draft: true |
| 65 | + prerelease: ${{ contains(github.event.ref, 'rc') }} |
| 66 | + - name: Upload Release Asset |
| 67 | + if: github.event.ref_type == 'tag' |
| 68 | + uses: actions/upload-release-asset@v1 |
| 69 | + env: |
| 70 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 71 | + with: |
| 72 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 73 | + asset_path: ./dist/${{ env.PACKAGE_NAME }}-${{ env.VERSION }}.tar.gz |
| 74 | + asset_name: ${{ env.PACKAGE_NAME }}-${{ env.VERSION }}.tar.gz |
| 75 | + asset_content_type: application/gzip |
| 76 | + - name: Publish on PyPI |
| 77 | + if: github.event.ref_type == 'tag' |
| 78 | + uses: pypa/gh-action-pypi-publish@master |
| 79 | + with: |
| 80 | + user: __token__ |
| 81 | + password: ${{ secrets.pypi }} |
0 commit comments