|
| 1 | +name: Publish |
| 2 | +on: |
| 3 | + release: |
| 4 | + types: [published] |
| 5 | + |
| 6 | +jobs: |
| 7 | + publish: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + outputs: |
| 10 | + release_number: ${{steps.get_latest_release_number.outputs.release_tag}} |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: write |
| 14 | + steps: |
| 15 | + - name: Checkout xero-python repo |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + repository: XeroAPI/xero-python |
| 19 | + path: xero-python |
| 20 | + |
| 21 | + - name: Set up Python environment |
| 22 | + uses: actions/setup-python@v5 |
| 23 | + with: |
| 24 | + python-version: '3.8' |
| 25 | + cache: 'pip' |
| 26 | + |
| 27 | + - name: Install dependencies |
| 28 | + run: | |
| 29 | + python -m venv venv |
| 30 | + source venv/bin/activate |
| 31 | + pip install --upgrade pip |
| 32 | + sudo pip install twine |
| 33 | + working-directory: xero-python |
| 34 | + |
| 35 | + - name: Fetch Latest release number |
| 36 | + id: get_latest_release_number |
| 37 | + run: | |
| 38 | + latest_version=$(gh release view --json tagName --jq '.tagName') |
| 39 | + echo "Latest release version is - $latest_version" |
| 40 | + echo "::set-output name=release_tag::$latest_version" |
| 41 | + working-directory: xero-python |
| 42 | + env: |
| 43 | + GH_TOKEN: ${{secrets.GITHUB_TOKEN}} |
| 44 | + |
| 45 | + - name: Build Package |
| 46 | + run: python setup.py sdist |
| 47 | + working-directory: xero-python |
| 48 | + |
| 49 | + - name: Publish to PyPi |
| 50 | + env: |
| 51 | + TWINE_USERNAME: __token__ |
| 52 | + TWINE_PASSWORD: ${{ secrets.PYPI_APIKEY }} |
| 53 | + run: twine upload dist/* |
| 54 | + working-directory: xero-python |
| 55 | + |
| 56 | + notify-slack-on-success: |
| 57 | + runs-on: ubuntu-latest |
| 58 | + needs: publish |
| 59 | + if: success() |
| 60 | + steps: |
| 61 | + - name: Checkout xero-pythonrepo |
| 62 | + uses: actions/checkout@v4 |
| 63 | + with: |
| 64 | + repository: XeroAPI/xero-python |
| 65 | + path: xero-python |
| 66 | + |
| 67 | + - name: Send slack notification on success |
| 68 | + uses: ./xero-python/.github/actions/notify-slack |
| 69 | + with: |
| 70 | + heading_text: "Publish job has succeeded !" |
| 71 | + alert_type: "thumbsup" |
| 72 | + job_status: "Success" |
| 73 | + XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}} |
| 74 | + job_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}" |
| 75 | + button_type: "primary" |
| 76 | + package_version: ${{needs.publish.outputs.release_number}} |
| 77 | + repo_link: ${{github.server_url}}/${{github.repository}} |
| 78 | + |
| 79 | + notify-slack-on-failure: |
| 80 | + runs-on: ubuntu-latest |
| 81 | + needs: publish |
| 82 | + if: failure() |
| 83 | + steps: |
| 84 | + - name: Checkout xero-python repo |
| 85 | + uses: actions/checkout@v4 |
| 86 | + with: |
| 87 | + repository: XeroAPI/xero-python |
| 88 | + path: xero-python |
| 89 | + |
| 90 | + - name: Send slack notification on failure |
| 91 | + uses: ./xero-python/.github/actions/notify-slack |
| 92 | + with: |
| 93 | + heading_text: "Publish job has failed !" |
| 94 | + alert_type: "alert" |
| 95 | + job_status: "Failed" |
| 96 | + XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}} |
| 97 | + job_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}" |
| 98 | + button_type: "danger" |
| 99 | + package_version: ${{needs.publish.outputs.release_number}} |
| 100 | + repo_link: ${{github.server_url}}/${{github.repository}} |
0 commit comments