diff --git a/.github/workflows/publish_main.yaml b/.github/workflows/publish_main.yaml new file mode 100644 index 00000000..fc12e85d --- /dev/null +++ b/.github/workflows/publish_main.yaml @@ -0,0 +1,77 @@ +name: Publish from Main + +on: + push: + branches: + - main + +permissions: + contents: write + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.11" + + - name: Install dependencies + run: pip install build twine tomli + + - name: Extract version from pyproject.toml + id: get_version + run: | + python -c "import tomli; version=tomli.load(open('pyproject.toml', 'rb'))['project']['version']; print(version)" > version.txt + echo "version=$(cat version.txt)" >> $GITHUB_OUTPUT + + - name: Determine Tag Name + id: determine_tag + run: | + version="${{ steps.get_version.outputs.version }}" + tag_name="v${version}" + echo "tag_name=$tag_name" >> $GITHUB_OUTPUT + + - name: Check if tag exists on GitHub + id: check_tag + uses: actions/github-script@v6 + with: + script: | + const tagName = "${{ steps.determine_tag.outputs.tag_name }}"; + const { data: tags } = await github.request('GET /repos/{owner}/{repo}/tags', { + owner: context.repo.owner, + repo: context.repo.repo + }); + const tagExists = tags.some(tag => tag.name === tagName); + core.info(`TAG_EXISTS=${tagExists.toString()}`); + core.exportVariable('TAG_EXISTS', tagExists.toString()); + + - name: Fail if tag already exists + if: env.TAG_EXISTS == 'true' + run: | + echo "Tag ${{ steps.determine_tag.outputs.tag_name }} already exists for this version. Cannot create a new release." + + - name: Build package + if: env.TAG_EXISTS == 'false' + run: python -m build + + - name: Create GitHub Release + if: env.TAG_EXISTS == 'false' + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ steps.determine_tag.outputs.tag_name }} + name: ${{ steps.determine_tag.outputs.tag_name }} + body: "Release for version ${{ steps.determine_tag.outputs.tag_name }}" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Publish to PyPI + if: env.TAG_EXISTS == 'false' + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} + run: twine upload dist/* diff --git a/.github/workflows/release-vame-package.yaml b/.github/workflows/release-vame-package.yaml deleted file mode 100644 index c9f0b948..00000000 --- a/.github/workflows/release-vame-package.yaml +++ /dev/null @@ -1,36 +0,0 @@ -name: Build and Release - -on: - push: - branches: - - main - - workflow_run: - workflows: ["Testing"] - branches: [main] - types: - - completed - -jobs: - pypi-release: - name: Release VAME in pypi - runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.conclusion == 'success' }} - steps: - - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v3 - with: - python-version: "3.11" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install build - pip install twine - - name: Build and publish to PyPI - run: | - python -m build - twine upload dist/* - env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} \ No newline at end of file