diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8701429..5777920 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,26 +1,86 @@ name: Publish to PyPI on: - release: - types: - - created + workflow_dispatch: + inputs: + test_publish: + description: "Publish to test PyPI" + type: boolean + default: false + + push: + branches: + - "main" + paths: + - ".github/workflows/publish.yml" + - "aws_fusion/**" + - "setup.py" concurrency: publish +env: + PYTHON_VERSION: '3.11' + jobs: - build: + tagging: runs-on: ubuntu-latest - environment: pypi + name: Auto Tagging + permissions: + contents: write + outputs: + tag: ${{ steps.package_info.outputs.tag }} + tag_pre_exist: ${{ steps.package_info.outputs.tag_pre_exist }} + steps: + - name: Checkout 🔔 + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Get package information + id: package_info + run: | + current_version=$(./setup.py --version) + + tag_pre_exist=false + if git rev-parse "refs/tags/v$current_version" >/dev/null 2>&1; then + echo "::warning title=Tag already exists::v${current_version}" + tag_pre_exist=true + fi + + echo "tag=v${current_version}" >> "$GITHUB_OUTPUT" + echo "tag_pre_exist=${tag_pre_exist}" >> "$GITHUB_OUTPUT" + + - name: Add git tag + if: ${{ steps.package_info.outputs.tag_pre_exist == 'false' }} + run: | + git tag ${{ steps.package_info.outputs.tag }} + git push origin ${{ steps.package_info.outputs.tag }} + + publish: + needs: tagging + if: ${{ inputs.test_publish || needs.tagging.outputs.tag_pre_exist == 'false' }} + runs-on: ubuntu-latest + name: Publish + environment: + name: pypi + url: "https://${{ inputs.test_publish && 'test.' || '' }}pypi.org/project/aws-fusion" permissions: id-token: write steps: - - name: Checkout code + - name: Checkout 🔔 uses: actions/checkout@v3 + with: + ref: ${{ needs.tagging.outputs.tag }} - name: Set up Python uses: actions/setup-python@v4 with: - python-version: '3.11' + python-version: ${{ env.PYTHON_VERSION }} - name: Install dependencies run: | @@ -28,8 +88,15 @@ jobs: pip install setuptools wheel twine - name: Build - run: | - python setup.py sdist bdist_wheel + run: python setup.py sdist bdist_wheel - name: Publish release distributions to PyPI + if: ${{ ! inputs.test_publish }} uses: pypa/gh-action-pypi-publish@release/v1 + + - name: Publish release distributions to Test PyPI + if: ${{ inputs.test_publish }} + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + diff --git a/.github/workflows/tagging.yml b/.github/workflows/tagging.yml deleted file mode 100644 index deb6e1d..0000000 --- a/.github/workflows/tagging.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: Auto Tagging - -on: - workflow_dispatch: - push: - branches: - - "main" - paths: - - "aws_fusion/**" - - "setup.py" - -concurrency: tagging - -jobs: - tag: - runs-on: ubuntu-latest - name: Auto Tagging - permissions: - contents: write - - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Setup Python - uses: actions/setup-python@v4 - with: - python-version: '3.11' - - - name: Get package information - id: package_info - run: | - current_version=$(./setup.py --version) - - tag_exist=false - if git rev-parse "refs/tags/v$current_version" >/dev/null 2>&1; then - echo "::warning title=Tag already exists::v${current_version}" - tag_exist=true - fi - - echo "tag=v${current_version}" >> "$GITHUB_OUTPUT" - echo "tag_exist=${tag_exist}" >> "$GITHUB_OUTPUT" - - - name: Add git tag - if: ${{ steps.package_info.outputs.tag_exist == 'false' }} - run: | - git tag ${{ steps.package_info.outputs.tag }} - git push origin ${{ steps.package_info.outputs.tag }} diff --git a/README.md b/README.md index 2dd80ac..04b0558 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Unified CLI tool for streamlined AWS operations, enhancing developer productivity [![Tag][tag-badge]][tag] -[![Tagging][actions-workflow-tagging-badge]][actions-workflow-tagging] +[![Publish][actions-workflow-publish-badge]][actions-workflow-publish] ## Installation Install via pip install @@ -144,5 +144,5 @@ This project is licensed under the MIT License - see the [LICENSE](./LICENSE) fi [tag]: https://github.com/snigdhasjg/aws-fusion/tags [tag-badge]: https://img.shields.io/github/v/tag/snigdhasjg/aws-fusion?style=for-the-badge&logo=github -[actions-workflow-tagging]: https://github.com/snigdhasjg/aws-fusion/actions/workflows/tagging.yml -[actions-workflow-tagging-badge]: https://img.shields.io/github/actions/workflow/status/snigdhasjg/aws-fusion/tagging.yml?branch=main&label=Tagging&style=for-the-badge&logo=githubactions +[actions-workflow-publish]: https://github.com/snigdhasjg/aws-fusion/actions/workflows/publish.yml +[actions-workflow-publish-badge]: https://img.shields.io/github/actions/workflow/status/snigdhasjg/aws-fusion/publish.yml?branch=main&label=Publish&style=for-the-badge&logo=githubactions