|
| 1 | +name: build and release openstackquery package |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'Version to release' |
| 8 | + required: true |
| 9 | + changelog: |
| 10 | + description: 'Release changelog description' |
| 11 | + required: false |
| 12 | + |
| 13 | +jobs: |
| 14 | + release: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + if: github.ref == 'refs/heads/main' |
| 18 | + |
| 19 | + strategy: |
| 20 | + matrix: |
| 21 | + python-version: ['3.8', '3.x'] |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout code |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Set up Python ${{ matrix.python-version }} |
| 28 | + uses: actions/setup-python@v4 |
| 29 | + with: |
| 30 | + python-version: ${{ matrix.python-version }} |
| 31 | + |
| 32 | + - name: Update version in setup.py |
| 33 | + run: | |
| 34 | + sed -i "s/version=.*,/version='${{ github.event.inputs.version }}',/" setup.py |
| 35 | +
|
| 36 | + - name: Install dependencies |
| 37 | + run: | |
| 38 | + python -m pip install --upgrade pip |
| 39 | + pip install setuptools wheel build |
| 40 | +
|
| 41 | + - name: Build package |
| 42 | + run: python -m build |
| 43 | + |
| 44 | + - name: Upload artifacts |
| 45 | + uses: actions/upload-artifact@v3 |
| 46 | + with: |
| 47 | + name: dist-${{ matrix.python-version }} |
| 48 | + path: dist/ |
| 49 | + |
| 50 | + publish: |
| 51 | + needs: release |
| 52 | + runs-on: ubuntu-latest |
| 53 | + |
| 54 | + steps: |
| 55 | + - name: Checkout code |
| 56 | + uses: actions/checkout@v4 |
| 57 | + |
| 58 | + - name: Download all artifacts |
| 59 | + uses: actions/download-artifact@v3 |
| 60 | + with: |
| 61 | + path: dist |
| 62 | + |
| 63 | + - name: Generate Changelog |
| 64 | + id: changelog |
| 65 | + run: | |
| 66 | + if [ -z "${{ github.event.inputs.changelog }}" ]; then |
| 67 | + echo "changelog=Release version ${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT |
| 68 | + else |
| 69 | + echo "changelog=${{ github.event.inputs.changelog }}" >> $GITHUB_OUTPUT |
| 70 | + fi |
| 71 | +
|
| 72 | + - name: Create Git Tag |
| 73 | + run: | |
| 74 | + git config user.name github-actions |
| 75 | + git config user.email github-actions@github.com |
| 76 | + git add version.txt |
| 77 | + git commit -m "Bump version to ${{ github.event.inputs.version }}" |
| 78 | + git tag v${{ github.event.inputs.version }} |
| 79 | + git push origin main |
| 80 | + git push origin v${{ github.event.inputs.version }} |
| 81 | +
|
| 82 | + - name: Create GitHub Release |
| 83 | + uses: softprops/action-gh-release@v1 |
| 84 | + with: |
| 85 | + tag_name: v${{ github.event.inputs.version }} |
| 86 | + body: ${{ steps.changelog.outputs.changelog }} |
| 87 | + files: | |
| 88 | + dist/**/*.whl |
| 89 | + dist/**/*.tar.gz |
| 90 | + env: |
| 91 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments