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