|
| 1 | +name: Publish & Release SDK |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + inputs: |
| 5 | + cab_id: |
| 6 | + description: "CAB id for the change/release" |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + |
| 10 | +jobs: |
| 11 | + publish: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + environment: prod |
| 14 | + outputs: |
| 15 | + release_number: ${{steps.get_latest_release_number.outputs.release_tag}} |
| 16 | + permissions: |
| 17 | + contents: write |
| 18 | + pull-requests: write |
| 19 | + steps: |
| 20 | + - name: Checkout xero-python repo |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + repository: XeroAPI/xero-python |
| 24 | + path: xero-python |
| 25 | + |
| 26 | + - name: Set up Python environment |
| 27 | + uses: actions/setup-python@v5 |
| 28 | + with: |
| 29 | + python-version: '3.8' |
| 30 | + cache: 'pip' |
| 31 | + |
| 32 | + - name: Install dependencies |
| 33 | + run: | |
| 34 | + python -m venv venv |
| 35 | + source venv/bin/activate |
| 36 | + pip install --upgrade pip |
| 37 | + sudo pip install twine |
| 38 | + working-directory: xero-python |
| 39 | + |
| 40 | + - name: Fetch Latest release number |
| 41 | + id: get_latest_release_number |
| 42 | + run: | |
| 43 | + latest_version=$(gh release view --json tagName --jq '.tagName') |
| 44 | + echo "Latest release version is - $latest_version" |
| 45 | + echo "::set-output name=release_tag::$latest_version" |
| 46 | + working-directory: xero-python |
| 47 | + env: |
| 48 | + GH_TOKEN: ${{secrets.GITHUB_TOKEN}} |
| 49 | + |
| 50 | + - name: Build Package |
| 51 | + run: python setup.py sdist |
| 52 | + working-directory: xero-python |
| 53 | + |
| 54 | + - name: Publish to PyPi |
| 55 | + env: |
| 56 | + TWINE_USERNAME: __token__ |
| 57 | + TWINE_PASSWORD: ${{ secrets.PYPI_APIKEY }} |
| 58 | + run: twine upload dist/* |
| 59 | + working-directory: xero-python |
| 60 | + |
| 61 | + notify-slack-on-success: |
| 62 | + runs-on: ubuntu-latest |
| 63 | + needs: publish |
| 64 | + if: success() |
| 65 | + permissions: |
| 66 | + contents: read |
| 67 | + steps: |
| 68 | + - name: Checkout xero-pythonrepo |
| 69 | + uses: actions/checkout@v4 |
| 70 | + with: |
| 71 | + repository: XeroAPI/xero-python |
| 72 | + path: xero-python |
| 73 | + |
| 74 | + - name: Send slack notification on success |
| 75 | + uses: ./xero-python/.github/actions/notify-slack |
| 76 | + with: |
| 77 | + heading_text: "Publish job has succeeded !" |
| 78 | + alert_type: "thumbsup" |
| 79 | + job_status: "Success" |
| 80 | + XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}} |
| 81 | + job_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}" |
| 82 | + button_type: "primary" |
| 83 | + package_version: ${{needs.publish.outputs.release_number}} |
| 84 | + repo_link: ${{github.server_url}}/${{github.repository}} |
| 85 | + |
| 86 | + notify-slack-on-failure: |
| 87 | + runs-on: ubuntu-latest |
| 88 | + needs: publish |
| 89 | + if: failure() |
| 90 | + permissions: |
| 91 | + contents: read |
| 92 | + steps: |
| 93 | + - name: Checkout xero-python repo |
| 94 | + uses: actions/checkout@v4 |
| 95 | + with: |
| 96 | + repository: XeroAPI/xero-python |
| 97 | + path: xero-python |
| 98 | + |
| 99 | + - name: Send slack notification on failure |
| 100 | + uses: ./xero-python/.github/actions/notify-slack |
| 101 | + with: |
| 102 | + heading_text: "Publish job has failed !" |
| 103 | + alert_type: "alert" |
| 104 | + job_status: "Failed" |
| 105 | + XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}} |
| 106 | + job_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}" |
| 107 | + button_type: "danger" |
| 108 | + package_version: ${{needs.publish.outputs.release_number}} |
| 109 | + repo_link: ${{github.server_url}}/${{github.repository}} |
| 110 | + |
| 111 | + notify-codegen-repo: |
| 112 | + needs: publish |
| 113 | + if: always() |
| 114 | + runs-on: ubuntu-latest |
| 115 | + permissions: |
| 116 | + contents: write |
| 117 | + pull-requests: write |
| 118 | + |
| 119 | + steps: |
| 120 | + - name: Checkout |
| 121 | + uses: actions/checkout@v4 |
| 122 | + with: |
| 123 | + repository: XeroAPI/xero-python |
| 124 | + path: xero-python |
| 125 | + |
| 126 | + - name: Install octokit dependencies |
| 127 | + run: npm i |
| 128 | + working-directory: xero-python/.github/octokit |
| 129 | + |
| 130 | + - name: Get github app access token |
| 131 | + id: get_access_token |
| 132 | + env: |
| 133 | + GITHUB_APP_ID: ${{ secrets.XERO_CODEGEN_BOT_APPLICATION_ID }} |
| 134 | + GITHUB_APP_PRIVATE_KEY: ${{ secrets.XERO_CODEGEN_BOT_APPLICATION_KEY }} |
| 135 | + uses: actions/github-script@v7 |
| 136 | + with: |
| 137 | + result-encoding: string |
| 138 | + script: | |
| 139 | + const { getAccessToken } = await import('${{ github.workspace }}/xero-python/.github/octokit/index.js') |
| 140 | + const token = await getAccessToken() |
| 141 | + return token |
| 142 | +
|
| 143 | + - name: Notify codegen repo |
| 144 | + run: | |
| 145 | + curl -X POST -H "Authorization: token ${{ steps.get_access_token.outputs.result }}" \ |
| 146 | + -H "Accept: application/vnd.github.v3+json" \ |
| 147 | + -H "Content-Type: application/json" \ |
| 148 | + https://api.github.com/repos/xero-internal/xeroapi-sdk-codegen/actions/workflows/notify-sdk-publish.yml/dispatches \ |
| 149 | + -d '{ |
| 150 | + "ref": "master", |
| 151 | + "inputs": { |
| 152 | + "commit": "${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}", |
| 153 | + "status": "${{needs.publish.result}}", |
| 154 | + "deployer": "xero-codegen-bot", |
| 155 | + "url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}", |
| 156 | + "environment": "prod", |
| 157 | + "sdk_type": "python", |
| 158 | + "cab_key": "${{ github.event.inputs.cab_id }}" |
| 159 | + } |
| 160 | + }' |
0 commit comments