|
13 | 13 | - "main" |
14 | 14 | paths: |
15 | 15 | - "aws_fusion/__init__.py" |
| 16 | + |
| 17 | + pull_request: |
| 18 | + branches: |
| 19 | + - "main" |
16 | 20 |
|
17 | 21 | concurrency: publish |
18 | 22 |
|
19 | 23 | env: |
20 | 24 | PYTHON_VERSION: '3.11' |
| 25 | + TEST_PUBLISH: ${{ inputs.test_publish && inputs.test_publish || github.event_name == 'pull_request' }} |
21 | 26 |
|
22 | 27 | jobs: |
23 | | - tagging: |
| 28 | + publish: |
24 | 29 | runs-on: ubuntu-latest |
25 | | - name: Auto Tagging |
| 30 | + name: Publish |
26 | 31 | permissions: |
27 | 32 | contents: write |
28 | | - outputs: |
29 | | - tag: ${{ steps.package_info.outputs.tag }} |
30 | | - tag_pre_exist: ${{ steps.package_info.outputs.tag_pre_exist }} |
| 33 | + id-token: write |
| 34 | + environment: |
| 35 | + name: pypi |
| 36 | + url: "https://${{ env.TEST_PUBLISH && 'test.' || '' }}pypi.org/project/aws-fusion" |
31 | 37 | steps: |
32 | 38 | - name: Checkout 🔔 |
33 | | - uses: actions/checkout@v3 |
| 39 | + uses: actions/checkout@v4 |
34 | 40 | with: |
35 | 41 | fetch-depth: 0 |
36 | 42 |
|
37 | 43 | - name: Setup Python |
38 | 44 | uses: actions/setup-python@v4 |
39 | 45 | with: |
40 | 46 | python-version: ${{ env.PYTHON_VERSION }} |
41 | | - |
42 | | - - name: Get package information |
| 47 | + |
| 48 | + - name: Package Info |
43 | 49 | id: package_info |
44 | 50 | run: | |
45 | 51 | current_version=$(./setup.py --version) |
46 | | - |
47 | | - tag_pre_exist=false |
48 | | - if git rev-parse "refs/tags/v$current_version" >/dev/null 2>&1; then |
49 | | - echo "::warning title=Tag already exists::v${current_version}" |
50 | | - tag_pre_exist=true |
| 52 | +
|
| 53 | + if [[ "${{ env.TEST_PUBLISH }}" == "true" ]]; then |
| 54 | + updated_version="${current_version}-${{ github.run_number }}" |
| 55 | + sed -iE "s|(__version__\s+=\s['\"])${current_version}(['\"])|\1${updated_version}\2|g" aws_fusion/__init__.py |
| 56 | + cat aws_fusion/__init__.py |
| 57 | + current_version="${updated_version}" |
51 | 58 | fi |
52 | | - |
53 | | - echo "tag=v${current_version}" >> "$GITHUB_OUTPUT" |
54 | | - echo "tag_pre_exist=${tag_pre_exist}" >> "$GITHUB_OUTPUT" |
55 | | - |
| 59 | +
|
| 60 | + echo "::notice file=aws_fusion/__init__.py::version=${current_version}" |
| 61 | + echo "version=${current_version}" >> "$GITHUB_OUTPUT" |
| 62 | + |
56 | 63 | - name: Add git tag |
57 | | - if: ${{ steps.package_info.outputs.tag_pre_exist == 'false' }} |
| 64 | + if: ${{ !env.TEST_PUBLISH }} |
58 | 65 | run: | |
59 | | - git tag ${{ steps.package_info.outputs.tag }} |
60 | | - git push origin ${{ steps.package_info.outputs.tag }} |
61 | | -
|
62 | | - publish: |
63 | | - needs: tagging |
64 | | - if: ${{ inputs.test_publish || needs.tagging.outputs.tag_pre_exist == 'false' }} |
65 | | - runs-on: ubuntu-latest |
66 | | - name: "${{ inputs.test_publish && 'Test ' || '' }}Publish" |
67 | | - environment: |
68 | | - name: pypi |
69 | | - url: "https://${{ inputs.test_publish && 'test.' || '' }}pypi.org/project/aws-fusion" |
70 | | - permissions: |
71 | | - id-token: write |
72 | | - steps: |
73 | | - - name: Checkout 🔔 |
74 | | - uses: actions/checkout@v3 |
75 | | - with: |
76 | | - ref: ${{ needs.tagging.outputs.tag }} |
| 66 | + tag="v${{ steps.package_info.outputs.version }}" |
77 | 67 |
|
78 | | - - name: Set up Python |
79 | | - uses: actions/setup-python@v4 |
80 | | - with: |
81 | | - python-version: ${{ env.PYTHON_VERSION }} |
| 68 | + git tag ${tag} |
| 69 | + git push origin ${tag} |
82 | 70 |
|
83 | 71 | - name: Install dependencies |
84 | 72 | run: | |
|
91 | 79 | - name: Publish release distributions to PyPI |
92 | 80 | uses: pypa/gh-action-pypi-publish@release/v1 |
93 | 81 | with: |
94 | | - repository-url: ${{ inputs.test_publish && 'https://test.pypi.org/legacy/' || '' }} |
| 82 | + repository-url: ${{ env.TEST_PUBLISH && 'https://test.pypi.org/legacy/' || '' }} |
95 | 83 |
|
0 commit comments