-
Notifications
You must be signed in to change notification settings - Fork 0
146 lines (140 loc) Β· 4.78 KB
/
test.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
on:
push:
branches:
- "*"
- "!main"
name: π₯ Test Workflow
jobs:
setup:
name: π οΈ Set Up
runs-on: ubuntu-latest
steps:
- name: π Git checkout
uses: actions/checkout@v4
- name: π Make sure repository is latest
run: git fetch --prune --unshallow
- name: π οΈ Install dependencies
run: composer install --no-interaction
- name: π¦ Create vendor archive
run: zip -r vendor.zip vendor
- name: π¦ Upload vendor folder
uses: actions/upload-artifact@v3
with:
name: vendor
path: vendor.zip
phpstan:
needs: setup
name: π¦ PHPStan analysis
runs-on: ubuntu-latest
steps:
- name: π Git checkout
uses: actions/checkout@v4
- name: π¦ Download vendor folder
uses: actions/download-artifact@v3
with:
name: vendor
- name: π¦ Extract vendor archive
run: unzip vendor.zip
- name: π¦ Analyze with PHPStan
run: composer phpstan
phpunit:
needs: setup
name: β
Run phpunit
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: testing
MYSQL_DATABASE: larapulse
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: π Git checkout
uses: actions/checkout@v4
- name: π¦ Download vendor folder
uses: actions/download-artifact@v3
with:
name: vendor
- name: π¦ Extract vendor archive
run: unzip vendor.zip
- name: π Set up php
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
- name: π Create environment
run: cp .env.example .env
- name: π Generate app key
run: php artisan key:generate
- name: π½ Running database migrate
run: php artisan migrate --env=testing
- name: π± Run database seeder
run: php artisan db:seed --class='Database\Seeders\TestingSeeder' --env=testing
- name: πΊοΈ Check routes
run: php artisan route:clear && php artisan route:list
- name: β
Run php tests
run: vendor/bin/phpunit
cleanup:
name: π§Ή Cleaning up artifact
runs-on: ubuntu-latest
needs: [setup, phpstan, phpunit]
steps:
- name: π Git checkout
uses: actions/checkout@v4
- name: π¦ Delete vendor artifact
uses: geekyeggo/delete-artifact@v2
with:
name: vendor
tagging:
needs: [setup, phpstan, phpunit]
name: π·οΈ Tagging the app
runs-on: ubuntu-latest
steps:
- name: π Git checkout
uses: actions/checkout@v4
- name: π Make sure repository is latest
run: git fetch --prune --unshallow
- name: π Create tag
uses: kangketikonlen/base-tagging@main
env:
REPO_NAME: ${{ github.event.repository.name }}
REPO_TYPE: ${{ github.event.repository.owner.type }}
REPO_OWNER: ${{ github.event.repository.owner.name }}
PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
PRESERVE_VERSION: 5
create-pr:
needs: [setup, phpstan, phpunit, cleanup, tagging]
name: π Create Pull Request
runs-on: ubuntu-latest
environment: testing
steps:
- name: π₯ Checkout code
uses: actions/checkout@v4
- name: π Install jq
run: sudo apt-get update && sudo apt-get install -y jq
- name: π Create PR
run: |
# Set up authentication
echo "${{ secrets.PERSONAL_TOKEN }}" >> token.txt
gh auth login --with-token < token.txt
rm -rf token.txt
# Get the current branch name
CURRENT_BRANCH=$(echo "${GITHUB_REF}" | awk -F'/' '{print $3}')
# Check if a pull request already exists
EXISTING_PR=$(gh pr list --state open --base main --head "${CURRENT_BRANCH}" --json number | jq -r '.[0].number')
# If a pull request exists, exit the workflow
if [[ "$EXISTING_PR" == null ]]; then
# Get the current date and time in the specified format
CURRENT_DATE=$(TZ='Asia/Jakarta' date +'%d-%m-%Y %H:%M')
# Create a pull request with date and time in the title
PR_TITLE="[$CURRENT_DATE] $CURRENT_BRANCH - Request merge $CURRENT_BRANCH to main branch"
gh pr create \
--base main \
--head "${CURRENT_BRANCH}" \
--title "${PR_TITLE}" \
--body "Automated pull request from ${CURRENT_BRANCH} to main branch"
else
echo "Pull request ${CURRENT_BRANCH} already exists ${EXISTING_PR}. Skipping PR creation."
exit 0
fi