diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e5ac2f9d..fd9e9132 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,43 +2,61 @@ name: Deploy Release on: workflow_dispatch: - release: + release: types: [published] + jobs: - tag-release: + tag-release: runs-on: ubuntu-latest + outputs: + version: ${{ steps.get_version.outputs.version }} + tag: ${{ steps.get_version.outputs.tag }} steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 - with: + with: python-version: '3.12' - name: Extract version from pyproject.toml id: get_version run: | VERSION=$(python -c " - try: + try: import tomllib with open('pyproject.toml', 'rb') as f: data = tomllib.load(f) print(data['project']['version']) except Exception as e: + import sys print(f'Error reading version: {e}', file=sys.stderr) exit(1) ") echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "tag=v$VERSION" >> $GITHUB_OUTPUT + + - name: Check if tag exists + id: check_tag + run: | + if git ls-remote --tags origin | grep -q "refs/tags/v${{ steps.get_version.outputs.version }}"; then + echo "Tag already exists" + echo "exists=true" >> $GITHUB_OUTPUT + else + echo "Tag does not exist" + echo "exists=false" >> $GITHUB_OUTPUT + fi - name: Tag the release + if: steps.check_tag.outputs.exists == 'false' run: | git config user.name "github-actions" git config user.email "github-actions@github.com" git tag v${{ steps.get_version.outputs.version }} git push origin v${{ steps.get_version.outputs.version }} - deploy-pypi: + deploy-pypi: needs: tag-release uses: ./.github/workflows/deploy-pypi.yml secrets: @@ -56,5 +74,7 @@ jobs: uses: ./.github/workflows/deploy-pyinstaller.yml upload-release: - needs: [deploy-pypi, deploy-dockerhub, deploy-pyinstaller] + needs: [tag-release, deploy-pypi, deploy-dockerhub, deploy-pyinstaller] uses: ./.github/workflows/upload-artifacts.yml + with: + tag_name: ${{ needs.tag-release.outputs.tag }} \ No newline at end of file diff --git a/.github/workflows/upload-artifacts.yml b/.github/workflows/upload-artifacts.yml index eaf767bf..809a6f64 100644 --- a/.github/workflows/upload-artifacts.yml +++ b/.github/workflows/upload-artifacts.yml @@ -1,14 +1,19 @@ name: Upload Release Artifacts on: - workflow_call: + workflow_call: + inputs: + tag_name: + required: true + type: string + jobs: - upload-release: + upload-release: runs-on: ubuntu-latest steps: - name: Download CPU installer package artifacts uses: actions/download-artifact@v4 - with: + with: pattern: "*-cpu-*" path: artifacts @@ -18,6 +23,7 @@ jobs: - name: Upload artifacts to GitHub Release uses: softprops/action-gh-release@v2 with: + tag_name: ${{ inputs.tag_name }} files: artifacts/*-cpu-*/* env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file