Skip to content

Commit 3085457

Browse files
PETOSS 733 | Automation | SDK pipeline | Enable the SDK publish pipeline (#392)
PETOSS 733 | Automation | SDK pipeline | Enable the SDK publish pipeline (#392)
1 parent de5fedf commit 3085457

File tree

2 files changed

+183
-0
lines changed

2 files changed

+183
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: slack-alert-action
2+
description: "Action to send slack payload to public-sdk-events channel"
3+
4+
inputs:
5+
heading_text:
6+
required: true
7+
description: "Heading of the slack payload"
8+
alert_type:
9+
required: true
10+
description: "type of the slack alert"
11+
job_status:
12+
required: true
13+
description: "status of the job"
14+
XERO_SLACK_WEBHOOK_URL:
15+
required: true
16+
description: "webhook url for channel - public-sdk-events"
17+
job_url:
18+
required: true
19+
description: "job run id link"
20+
button_type:
21+
required: true
22+
description: "color for the check logs button"
23+
package_version:
24+
required: true
25+
description: "released package version"
26+
repo_link:
27+
required: true
28+
description: "link of the repo"
29+
30+
31+
runs:
32+
using: "composite"
33+
34+
steps:
35+
36+
- name: Send slack notification
37+
id: slack
38+
uses: slackapi/[email protected]
39+
env:
40+
SLACK_WEBHOOK_URL: ${{inputs.XERO_SLACK_WEBHOOK_URL}}
41+
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
42+
with:
43+
payload: |
44+
{
45+
"blocks": [
46+
{
47+
"type": "rich_text",
48+
"elements": [
49+
{
50+
"type": "rich_text_section",
51+
"elements": [
52+
{
53+
"type": "text",
54+
"text": "${{inputs.heading_text}} ",
55+
"style": {
56+
"bold": true
57+
}
58+
},
59+
{
60+
"type": "emoji",
61+
"name": "${{inputs.alert_type}}"
62+
}
63+
]
64+
}
65+
]
66+
},
67+
{
68+
"type": "divider"
69+
},
70+
{
71+
"type": "section",
72+
"fields": [
73+
{
74+
"type": "mrkdwn",
75+
"text": "*Repository:* \n ${{inputs.repo_link}}"
76+
},
77+
{
78+
"type": "mrkdwn",
79+
"text": "*Status:*\n ${{inputs.job_status}}"
80+
},
81+
{
82+
"type": "mrkdwn",
83+
"text": "*Package Version:*\n ${{inputs.package_version}}"
84+
}
85+
]
86+
},
87+
{
88+
"type": "actions",
89+
"elements": [
90+
{
91+
"type": "button",
92+
"text": {
93+
"type": "plain_text",
94+
"text": "Check the logs",
95+
"emoji": true
96+
},
97+
"style": "${{inputs.button_type}}",
98+
"url": "${{inputs.job_url}}"
99+
}
100+
]
101+
}
102+
]
103+
}

.github/workflows/check-publish.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Check Packagist Publish
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
check-publish:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
13+
steps:
14+
15+
- name: Checkout repo
16+
uses: actions/checkout@v4
17+
with:
18+
repository: XeroAPI/xero-php-oauth2
19+
path: xero-php-oauth2
20+
21+
- name: Fetch Latest release number
22+
id: get_latest_release_number
23+
run: |
24+
latest_version=$(gh release view --json tagName --jq '.tagName')
25+
echo "Latest release version is - $latest_version"
26+
echo "php_version=${latest_version}" >> $GITHUB_ENV
27+
working-directory: xero-php-oauth2
28+
env:
29+
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
30+
31+
- name: Get latest version from packgist
32+
id: get_packagist_version
33+
run: |
34+
RESPONSE=$(curl -s https://repo.packagist.org/p2/xeroapi/xero-php-oauth2.json)
35+
LATEST_VERSION=$(echo $RESPONSE | jq -r '.packages["xeroapi/xero-php-oauth2"][0].version')
36+
echo "latest packagist version: $LATEST_VERSION"
37+
echo "latest_packagist_version=${LATEST_VERSION}" >> $GITHUB_ENV
38+
39+
- name: Compare versions
40+
id: compare_versions
41+
run: |
42+
if [ "${{env.php_version}}" == "${{env.latest_packagist_version}}" ]; then
43+
echo "Packagist is up-to-date"
44+
echo "packagist_status=success" >> $GITHUB_ENV
45+
else
46+
echo "Packagist is not updated yet"
47+
echo "packagist_status=failure" >> $GITHUB_ENV
48+
fi
49+
50+
- name: Send slack Notification on Success
51+
if: ${{ env.packagist_status == 'success' }}
52+
uses: ./xero-php-oauth2/.github/actions/notify-slack
53+
with:
54+
heading_text: "Publish job has succeeded !"
55+
alert_type: "thumbsup"
56+
job_status: "Success"
57+
XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}}
58+
job_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
59+
button_type: "primary"
60+
package_version: ${{env.php_version}}
61+
repo_link: ${{github.server_url}}/${{github.repository}}
62+
63+
- name: Send slack Notification on Failure
64+
if: ${{ env.packagist_status == 'failure' }}
65+
uses: ./xero-php-oauth2/.github/actions/notify-slack
66+
with:
67+
heading_text: "Publish job has failed !"
68+
alert_type: "alert"
69+
job_status: "Failed"
70+
XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}}
71+
job_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
72+
button_type: "danger"
73+
package_version: ${{env.php_version}}
74+
repo_link: ${{github.server_url}}/${{github.repository}}
75+
76+
- name: Fail job if status is Failure
77+
if: ${{env.packagist_status == 'failure'}}
78+
run: |
79+
echo "Job failed because packagist is not updated"
80+
exit 1

0 commit comments

Comments
 (0)