|
| 1 | +name: "Publish new release" |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - v[0-9]+.* |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + types: |
| 11 | + - closed |
| 12 | + |
| 13 | +jobs: |
| 14 | + release: |
| 15 | + name: Build wheels |
| 16 | + runs-on: ubuntu-latest |
| 17 | + if: startsWith(github.ref, 'refs/tags/') || (github.event_name == 'pull_request' && github.event.pull_request.merged == true) |
| 18 | + |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v2 |
| 21 | + |
| 22 | + - name: Get history and tags for SCM versioning to work |
| 23 | + run: | |
| 24 | + git fetch --prune --unshallow |
| 25 | + git fetch --depth=1 origin +refs/tags/*:refs/tags/* |
| 26 | +
|
| 27 | + - name: Extract version from tag name |
| 28 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') |
| 29 | + run: | |
| 30 | + TAG_NAME="${GITHUB_REF/refs\/tags\//}" |
| 31 | + VERSION=${TAG_NAME#v} |
| 32 | + echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV |
| 33 | +
|
| 34 | + - name: Extract version from branch name (for release branches) |
| 35 | + if: github.event_name == 'pull_request' && startsWith(github.event.pull_request.head.ref, 'release/') |
| 36 | + run: | |
| 37 | + BRANCH_NAME="${{ github.event.pull_request.head.ref }}" |
| 38 | + VERSION=${BRANCH_NAME#release/} |
| 39 | + echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV |
| 40 | +
|
| 41 | + - name: Extract version from branch name (for hotfix branches) |
| 42 | + if: github.event_name == 'pull_request' && startsWith(github.event.pull_request.head.ref, 'hotfix/') |
| 43 | + run: | |
| 44 | + BRANCH_NAME="${{ github.event.pull_request.head.ref }}" |
| 45 | + VERSION=${BRANCH_NAME#hotfix/} |
| 46 | + echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV |
| 47 | +
|
| 48 | + - name: Set tag for setuptools-scm |
| 49 | + run: git tag v${RELEASE_VERSION} main |
| 50 | + |
| 51 | + - name: Build wheel |
| 52 | + run: | |
| 53 | + python -m pip install build wheel |
| 54 | + python -m build --wheel --sdist |
| 55 | +
|
| 56 | + - name: Check metadata |
| 57 | + run: | |
| 58 | + python3 -m pip install twine --prefer-binary |
| 59 | + python3 -m twine check dist/* |
| 60 | +
|
| 61 | + # Code below inspired from this action: |
| 62 | + # - uses: taiki-e/create-gh-release-action@v1 |
| 63 | + # with: |
| 64 | + # title: ProjectQ $tag |
| 65 | + # changelog: CHANGELOG.md |
| 66 | + # env: |
| 67 | + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 68 | + |
| 69 | + - name: Create release |
| 70 | + env: |
| 71 | + target: x86_64-unknown-linux-musl |
| 72 | + parse_changelog_tag: v0.3.0 |
| 73 | + changelog: CHANGELOG.md |
| 74 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + run: | |
| 76 | + # https://github.com/taiki-e/parse-changelog |
| 77 | + curl -LsSf "https://github.com/taiki-e/parse-changelog/releases/download/${parse_changelog_tag}/parse-changelog-${target}.tar.gz" | tar xzf - |
| 78 | + notes=$(./parse-changelog "${changelog}" "${RELEASE_VERSION}") |
| 79 | + rm -f ./parse-changelog |
| 80 | + if [[ "${tag}" =~ ^v?[0-9\.]+-[a-zA-Z_0-9\.-]+(\+[a-zA-Z_0-9\.-]+)?$ ]]; then |
| 81 | + prerelease="--prerelease" |
| 82 | + fi |
| 83 | + gh release create "v${RELEASE_VERSION}" ${prerelease:-} --title "ProjectQ v${RELEASE_VERSION}" --notes "${notes:-}" dist/* |
| 84 | +
|
| 85 | + - name: Setup Python for Pypi upload |
| 86 | + uses: actions/setup-python@v2 |
| 87 | + |
| 88 | + - name: Publish standard package |
| 89 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 90 | + with: |
| 91 | + user: __token__ |
| 92 | + password: ${{ secrets.pypi_password }} |
| 93 | + packages_dir: dist/ |
0 commit comments