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-ruby repo
21+ uses : actions/checkout@v4
22+ with :
23+ repository : XeroAPI/xero-ruby
24+ path : xero-ruby
25+
26+ - name : Fetch Latest release number
27+ id : get_latest_release_number
28+ run : |
29+ latest_version=$(gh release view --json tagName --jq '.tagName')
30+ echo "Latest release version is - $latest_version"
31+ echo "::set-output name=release_tag::$latest_version"
32+ working-directory : xero-ruby
33+ env :
34+ GH_TOKEN : ${{secrets.GITHUB_TOKEN}}
35+
36+ - name : Set up Ruby environment
37+ uses : ruby/setup-ruby@v1
38+ with :
39+ ruby-version : ' 3.2.0'
40+ bundler-cache : true
41+
42+ - name : Install dependencies
43+ run : bundle install
44+ working-directory : xero-ruby
45+
46+ - name : Publish to Ruby
47+ env :
48+ GEM_HOST_API_KEY : ${{ secrets.RUBYGEMS_API_KEY }}
49+ run : |
50+ gemspec_file=$(ls *.gemspec)
51+ gem_file=$(gem build "$gemspec_file" | grep -o '[^ ]*\.gem')
52+ echo "$gem_file"
53+ gem push "$gem_file"
54+ working-directory : xero-ruby
55+
56+ notify-slack-on-success :
57+ runs-on : ubuntu-latest
58+ needs : publish
59+ if : success()
60+ permissions :
61+ contents : read
62+ steps :
63+ - name : Checkout xero-ruby repo
64+ uses : actions/checkout@v4
65+ with :
66+ repository : XeroAPI/xero-ruby
67+ path : xero-ruby
68+
69+ - name : Send slack notification on success
70+ uses : ./xero-ruby/.github/actions/notify-slack
71+ with :
72+ heading_text : " Publish job has succeeded !"
73+ alert_type : " thumbsup"
74+ job_status : " Success"
75+ XERO_SLACK_WEBHOOK_URL : ${{secrets.XERO_SLACK_WEBHOOK_URL}}
76+ job_url : " https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
77+ button_type : " primary"
78+ package_version : ${{needs.publish.outputs.release_number}}
79+ repo_link : ${{github.server_url}}/${{github.repository}}
80+
81+ notify-slack-on-failure :
82+ runs-on : ubuntu-latest
83+ needs : publish
84+ if : failure()
85+ permissions :
86+ contents : read
87+ steps :
88+ - name : Checkout xero-ruby repo
89+ uses : actions/checkout@v4
90+ with :
91+ repository : XeroAPI/xero-ruby
92+ path : xero-ruby
93+
94+ - name : Send slack notification on failure
95+ uses : ./xero-ruby/.github/actions/notify-slack
96+ with :
97+ heading_text : " Publish job has failed !"
98+ alert_type : " alert"
99+ job_status : " Failed"
100+ XERO_SLACK_WEBHOOK_URL : ${{secrets.XERO_SLACK_WEBHOOK_URL}}
101+ job_url : " https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
102+ button_type : " danger"
103+ package_version : ${{needs.publish.outputs.release_number}}
104+ repo_link : ${{github.server_url}}/${{github.repository}}
105+ notify-codegen-repo :
106+ needs : publish
107+ if : always()
108+ runs-on : ubuntu-latest
109+ permissions :
110+ contents : write
111+ pull-requests : write
112+
113+ steps :
114+ - name : Checkout
115+ uses : actions/checkout@v4
116+ with :
117+ repository : XeroAPI/xero-ruby
118+ path : xero-ruby
119+
120+ - name : Install octokit dependencies
121+ run : npm i
122+ working-directory : xero-ruby/.github/octokit
123+
124+ - name : Get github app access token
125+ id : get_access_token
126+ env :
127+ GITHUB_APP_ID : ${{ secrets.XERO_CODEGEN_BOT_APPLICATION_ID }}
128+ GITHUB_APP_PRIVATE_KEY : ${{ secrets.XERO_CODEGEN_BOT_APPLICATION_KEY }}
129+ uses : actions/github-script@v7
130+ with :
131+ result-encoding : string
132+ script : |
133+ const { getAccessToken } = await import('${{ github.workspace }}/xero-ruby/.github/octokit/index.js')
134+ const token = await getAccessToken()
135+ return token
136+
137+ - name : Notify codegen repo
138+ run : |
139+ curl -X POST -H "Authorization: token ${{ steps.get_access_token.outputs.result }}" \
140+ -H "Accept: application/vnd.github.v3+json" \
141+ -H "Content-Type: application/json" \
142+ https://api.github.com/repos/xero-internal/xeroapi-sdk-codegen/actions/workflows/notify-sdk-publish.yml/dispatches \
143+ -d '{
144+ "ref": "master",
145+ "inputs": {
146+ "commit": "${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}",
147+ "status": "${{needs.publish.result}}",
148+ "deployer": "xero-codegen-bot",
149+ "url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
150+ "environment": "prod",
151+ "sdk_type": "ruby",
152+ "cab_key": "${{ github.event.inputs.cab_id }}"
153+ }
154+ }'
0 commit comments