From 0a3a6a2f90c232b507bf5dc30d67c2edb7e1ab7a Mon Sep 17 00:00:00 2001 From: Noritaka IZUMI <38166104+noritakaIzumi@users.noreply.github.com> Date: Mon, 4 Nov 2024 13:58:04 +0900 Subject: [PATCH] Fix create new release (#33) --- .github/workflows/build-pip-package.yml | 37 +++++++++++++++++++ .github/workflows/create-new-release.yml | 46 +++++++++++++++++++----- .github/workflows/publish.yml | 5 --- .github/workflows/test.yml | 1 - 4 files changed, 74 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/build-pip-package.yml diff --git a/.github/workflows/build-pip-package.yml b/.github/workflows/build-pip-package.yml new file mode 100644 index 0000000..b636ea7 --- /dev/null +++ b/.github/workflows/build-pip-package.yml @@ -0,0 +1,37 @@ +name: Build pip package + +on: + workflow_call: + inputs: + version: + description: Version string from hatch + type: string + required: true + +env: + app-name: "chronovoyage" + +jobs: + main: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Hatch + uses: pypa/hatch@install + + - name: Build Package + run: hatch build -c + + - name: Upload artifacts (sdist) + uses: actions/upload-artifact@v4 + with: + name: pip-package--sdist + path: dist/${{ env.app-name }}-${{ inputs.version }}.tar.gz + + - name: Upload artifacts (wheel) + uses: actions/upload-artifact@v4 + with: + name: pip-package--wheel + path: dist/${{ env.app-name }}-${{ inputs.version }}-py3-none-any.whl diff --git a/.github/workflows/create-new-release.yml b/.github/workflows/create-new-release.yml index 2212f3f..0748ee0 100644 --- a/.github/workflows/create-new-release.yml +++ b/.github/workflows/create-new-release.yml @@ -7,12 +7,19 @@ on: types: - closed +env: + tag-prefix: "v" + jobs: push-tag: + name: Push a tag if: ${{ contains(github.event.pull_request.labels.*.name, 'new release') && github.event.pull_request.merged }} runs-on: ubuntu-latest + permissions: + contents: write outputs: - tag: ${{ steps.tag.outputs.value }} + version: ${{ steps.tag.outputs.version }} + tag: ${{ steps.tag.outputs.tag }} steps: - name: Checkout repository uses: actions/checkout@v4 @@ -28,22 +35,43 @@ jobs: - name: Push a tag id: tag run: | - tag="v$(hatch version)" + version="$(hatch version)" + tag="${{ env.tag-prefix }}${version}" git tag -a ${tag} -m "New release ${tag} (tagged by github-actions[bot])" git push origin ${tag} - echo "value=${tag}" >> $GITHUB_OUTPUT + echo "version=${version}" >> $GITHUB_OUTPUT + echo "tag=${tag}" >> $GITHUB_OUTPUT + + build-package: + needs: + - push-tag + uses: ./.github/workflows/build-pip-package.yml + with: + version: ${{ needs.push-tag.outputs.version }} create-release: + name: Create a release runs-on: ubuntu-latest - needs: push-tag + needs: + - push-tag + - build-package + permissions: + contents: write steps: - name: Checkout repository uses: actions/checkout@v4 + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + path: dist + pattern: pip-package--* + merge-multiple: true + - name: Create a release - uses: elgohr/Github-Release-Action@v5 - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: softprops/action-gh-release@v2 with: - title: ${{ steps.tag.outputs.value }} - tag: ${{ steps.tag.outputs.value }} + draft: true + tag_name: ${{ needs.push-tag.outputs.tag }} + generate_release_notes: true + files: dist/* diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f64a58e..0d53df5 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -7,13 +7,8 @@ permissions: contents: read jobs: - test: - uses: ./.github/workflows/test.yml - publish: runs-on: ubuntu-latest - needs: - - test environment: release permissions: id-token: write diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e5569ee..dc66a2f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,6 @@ on: pull_request: branches: - main - workflow_call: workflow_dispatch: concurrency: