|
5 | 5 | branches: [main, master] |
6 | 6 | pull_request: |
7 | 7 | branches: [main, master] |
8 | | - release: |
9 | | - types: [published] |
10 | 8 |
|
11 | 9 | jobs: |
12 | 10 | test: |
@@ -99,10 +97,67 @@ jobs: |
99 | 97 | name: dist |
100 | 98 | path: dist/ |
101 | 99 |
|
| 100 | + release: |
| 101 | + needs: [test, lint, build] |
| 102 | + runs-on: ubuntu-latest |
| 103 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 104 | + permissions: |
| 105 | + contents: write |
| 106 | + outputs: |
| 107 | + released: ${{ steps.check_tag.outputs.exists == 'false' }} |
| 108 | + version: ${{ steps.version.outputs.version }} |
| 109 | + |
| 110 | + steps: |
| 111 | + - uses: actions/checkout@v4 |
| 112 | + with: |
| 113 | + fetch-depth: 0 |
| 114 | + |
| 115 | + - name: Download artifacts |
| 116 | + uses: actions/download-artifact@v4 |
| 117 | + with: |
| 118 | + name: dist |
| 119 | + path: dist/ |
| 120 | + |
| 121 | + - name: Get version |
| 122 | + id: version |
| 123 | + run: | |
| 124 | + VERSION=$(python -c "import sys; sys.path.insert(0, '.'); from cognipy import __version__; print(__version__)") |
| 125 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 126 | +
|
| 127 | + - name: Check if tag exists |
| 128 | + id: check_tag |
| 129 | + run: | |
| 130 | + if git rev-parse "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then |
| 131 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 132 | + else |
| 133 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 134 | + fi |
| 135 | +
|
| 136 | + - name: Create Release |
| 137 | + if: steps.check_tag.outputs.exists == 'false' |
| 138 | + uses: softprops/action-gh-release@v1 |
| 139 | + with: |
| 140 | + tag_name: v${{ steps.version.outputs.version }} |
| 141 | + name: Release v${{ steps.version.outputs.version }} |
| 142 | + body: | |
| 143 | + ## Version |
| 144 | + v${{ steps.version.outputs.version }} |
| 145 | + |
| 146 | + ## Build Info |
| 147 | + - Runner OS: ${{ runner.os }} |
| 148 | + - Build Time: ${{ github.event.head_commit.timestamp }} |
| 149 | + - Commit: ${{ github.sha }} |
| 150 | + - Branch: ${{ github.ref_name }} |
| 151 | + files: dist/* |
| 152 | + draft: false |
| 153 | + prerelease: false |
| 154 | + env: |
| 155 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 156 | + |
102 | 157 | publish: |
103 | | - needs: build |
| 158 | + needs: release |
104 | 159 | runs-on: ubuntu-latest |
105 | | - if: github.event_name == 'release' |
| 160 | + if: needs.release.outputs.released == 'true' |
106 | 161 | permissions: |
107 | 162 | id-token: write |
108 | 163 |
|
|
0 commit comments