-
Notifications
You must be signed in to change notification settings - Fork 2
106 lines (93 loc) · 3.43 KB
/
action-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
name: Action CI
on:
workflow_call:
permissions: {}
jobs:
ci:
name: CI
runs-on: ubuntu-latest
outputs:
latest_local_sha: ${{ steps.output-sha.outputs.latest_local_sha }}
has_auto_tag: ${{ steps.output-has-auto-tag.outputs.has_auto_tag }}
branch: ${{ steps.output-branch.outputs.branch }}
steps:
- name: Checkout code
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
- name: Install PHP
uses: shivammathur/setup-php@c541c155eee45413f5b09a52248675b1a2575231 # v2.31.1
with:
php-version: 8.1
extensions: yaml
tools: composer:v2
- name: Run CI
run: |
if [[ -f composer.json ]]; then
composer install --prefer-dist --no-progress --no-suggest --no-interaction --no-scripts --no-plugins
fi
if [[ -f phpunit.xml ]] || [[ -f phpunit.xml.dist ]]; then
if [[ -f vendor/bin/phpunit ]]; then
vendor/bin/phpunit
else
wget https://phar.phpunit.de/phpunit-9.6.phar
php phpunit-9.6.phar --verbose --colors=always
fi
else
echo "No phpunit tests found"
fi
- name: Output latest SHA
id: output-sha
run: |
LATEST_LOCAL_SHA=$(git rev-parse HEAD)
echo "LATEST_LOCAL_SHA is $LATEST_LOCAL_SHA"
echo "latest_local_sha=$LATEST_LOCAL_SHA" >> $GITHUB_OUTPUT
- name: Output has auto-tag
id: output-has-auto-tag
run: |
HAS_AUTO_TAG="false"
if [[ -f .github/workflows/auto-tag.yml ]]; then
HAS_AUTO_TAG="true"
fi
echo "HAS_AUTO_TAG is $HAS_AUTO_TAG"
echo "has_auto_tag=$HAS_AUTO_TAG" >> $GITHUB_OUTPUT
- name: Output branch
id: output-branch
run: |
BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "BRANCH is $BRANCH"
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
dispatchtagpatchrelase:
name: Dispatch tag patch release
runs-on: ubuntu-latest
needs: ci
if: ${{ github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
permissions:
actions: write
env:
GITHUB_REPOSITORY: ${{ github.repository }}
BRANCH: ${{ needs.ci.outputs.branch }}
steps:
- name: Dispatch tag patch release
shell: bash
id: dispatch-tag-patch-release
run: |
# https://docs.github.com/en/rest/actions/workflows?apiVersion=2022-11-28#create-a-workflow-dispatch-event
RESP_CODE=$(curl -w %{http_code} -s -L -o __response.json \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$GITHUB_REPOSITORY/actions/workflows/tag-patch-release.yml/dispatches \
-d "{\"ref\":\"$BRANCH\",\"inputs\":{\"latest_local_sha\":\"${{ needs.ci.outputs.latest_local_sha }}\"}}"
)
if [[ $RESP_CODE != "204" ]]; then
echo "Failed to dispatch workflow - HTTP response code was $RESP_CODE"
cat __response.json
exit 1
fi
- name: Delete temporary files
shell: bash
if: always()
run: |
if [[ -f __response.json ]]; then
rm __response.json
fi