-
Notifications
You must be signed in to change notification settings - Fork 1
199 lines (184 loc) · 8.01 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
name: Test
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *' # everyday at midnight
push:
branches:
- main
pull_request:
branches:
- main
jobs:
test:
name: Run tests
env:
# We need these for the setup job where we commit.
GIT_AUTHOR_NAME: violinist-bot
GIT_AUTHOR_EMAIL: [email protected]
GIT_COMMITTER_NAME: violinist-bot
GIT_COMMITTER_EMAIL: [email protected]
runs-on: ubuntu-24.04
services:
gitlab:
image: gitlab/gitlab-ce
ports:
- 2200:80
env:
# This password is lifted directly from the GitLab docker docs:
# https://docs.gitlab.com/ee/install/docker/installation.html#install-gitlab-by-using-docker-swarm-mode
GITLAB_OMNIBUS_CONFIG: "gitlab_rails['initial_root_password'] = 'MySuperSecretAndSecurePassw0rd!';"
strategy:
fail-fast: true
max-parallel: 2
matrix:
php-version:
- "7.3"
- "7.4"
- "8.0"
- "8.1"
- "8.2"
- "8.3"
- "8.4"
composer-version:
- "2"
steps:
- name: Dump matrix context
env:
MATRIX_CONTEXT: ${{ toJSON(matrix) }}
run: echo "$MATRIX_CONTEXT"
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
- name: Update composer
run: composer --verbose self-update --${{ matrix.composer-version }}
- name: Dump composer verson
run: composer --version
- name: Validate composer.json
run: composer --verbose validate
- name: Install dependencies
run: composer --verbose install
- name: Configure the GitLab instance
run: |
./vendor/bin/wait-for-listen 2200
attempt_counter=0
max_attempts=60
while true; do
echo "Waiting for the site to be up"
echo "Attempt number ${attempt_counter}"
if [ ${attempt_counter} -eq ${max_attempts} ];then
echo "Max attempts reached"
exit 1
fi
# Run a cURL request and check if the status is 200.
status=$(curl -o /dev/null --retry 3 --retry-all-errors -sL -w "%{http_code}\n" http://localhost:2200)
if [ "$status" -eq 200 ]; then
echo "Status is 200"
break
fi
echo $status
attempt_counter=$(($attempt_counter+1))
sleep 5
done
# Get an oauth token to use in subsequent calls:
# https://docs.gitlab.com/ee/api/oauth2.html#resource-owner-password-credentials-flow
echo 'grant_type=password&username=root&password=MySuperSecretAndSecurePassw0rd!&scope=api%20write_repository' > auth.txt
export token=$(curl --retry 12 --retry-all-errors --data "@auth.txt" --request POST --fail "http://localhost:2200/oauth/token" | jq -r '.access_token')
echo "Token retrieved"
# Create a super simple composer project and push to our new repo.
mkdir /tmp/test
cd /tmp/test
composer require psr/log 1.0.0
git init
git branch -m master
git add composer.*
git commit -m init
# We could theoretically use the oauth token here as well, but
# the tests will do that anyway.
git remote add origin http://root:MySuperSecretAndSecurePassw0rd!@localhost:2200/root/new-project
RETRIES_NO=5
RETRY_DELAY=3
for i in $(seq 1 $RETRIES_NO); do
git push -u origin master && break
[[ $i -eq $RETRIES_NO ]] && echo "Failed to execute git cmd after $RETRIES_NO retries" && exit 1
echo "retrying after $RETRY_DELAY"
sleep ${RETRY_DELAY}
done
# One of the tests is with a PAT. So create one:
# https://docs.gitlab.com/ee/api/user_tokens.html
# Todo: Would be nice to instead create a regular user and not use the root
# user here.
export pat=$(curl --retry 12 --retry-all-errors --request POST --fail --header "Authorization: Bearer $token" --data "name=mytoken" \
--data "scopes[]=api&scopes[]=write_repository" --url "http://localhost:2200/api/v4/users/1/personal_access_tokens" | jq -r '.token')
echo "token=$token" >> "$GITHUB_OUTPUT"
echo "pat=$pat" >> "$GITHUB_OUTPUT"
id: setup
- name: Build test image
run: docker build --build-arg COMPOSER_VERSION=$COMPOSER_VERSION --build-arg PHP_VERSION=$PHP_VERSION -t update-check-runner .
env:
COMPOSER_VERSION: ${{ matrix.composer-version }}
PHP_VERSION: ${{ matrix.php-version }}
- name: Run phpstan
run: composer phpstan
- run: |
git status
export MY_COMMIT=$(git log --format=format:%H -n1)
echo $MY_COMMIT
echo "COMMIT_SHA=$MY_COMMIT" >> $GITHUB_OUTPUT
id: log
- name: Coding style
run: composer phpcs
- name: Dump modules and ensure no diff
run: |
rm auth.txt
docker run --rm update-check-runner php -m > module-list/${{ matrix.php-version }}.txt
git status
cat module-list/${{ matrix.php-version }}.txt
php tests/produce-table.php
if [ $(git status -s | wc -c) -ne 0 ]; then
echo "Working tree is not clean:"
git status
git diff
exit 1
fi
- name: Run tests
run: ./vendor/bin/phpunit
env:
COMPOSER_VERSION: ${{ matrix.composer-version }}
PHP_VERSION: ${{ matrix.php-version }}
GITHUB_PRIVATE_USER_TOKEN: ${{ secrets.GH_PRIVATE_USER_TOKEN }}
GITHUB_PRIVATE_REPO: ${{ secrets.GH_PRIVATE_REPO }}
GITLAB_PRIVATE_REPO: ${{ secrets.GITLAB_PRIVATE_REPO }}
MY_COMMIT: ${{ steps.log.outputs.COMMIT_SHA }}
SELF_HOSTED_GITLAB_PRIVATE_USER_TOKEN: ${{ steps.setup.outputs.token }}
SELF_HOSTED_GITLAB_PRIVATE_REPO: http://172.17.0.1:2200/root/new-project
BITBUCKET_CLIENT_ID: ${{ secrets.BITBUCKET_CLIENT_ID }}
BITBUCKET_CLIENT_SECRET: ${{ secrets.BITBUCKET_CLIENT_SECRET }}
BITBUCKET_REDIRECT_URI: ${{ secrets.BITBUCKET_REDIRECT_URI }}
BITBUCKET_REFRESH_TOKEN: ${{ secrets.BITBUCKET_REFRESH_TOKEN }}
BITBUCKET_PRIVATE_REPO: ${{ secrets.BITBUCKET_PRIVATE_REPO }}
GITHUB_DRUPAL8_CONTRIB_PRIVATE_REPO: ${{ secrets.GH_DRUPAL8_CONTRIB_PRIVATE_REPO }}
GITLAB_PRIVATE_REPO_NESTED_GROUP: ${{ secrets.GITLAB_PRIVATE_REPO_NESTED_GROUP }}
GITHUB_PUBLIC_REPO: ${{ secrets.GH_PUBLIC_REPO }}
GITHUB_PUBLIC_PROJECT_NID: ${{ secrets.GH_PUBLIC_PROJECT_NID }}
GITHUB_FORK_TO: ${{ secrets.GH_FORK_TO }}
TOKEN_URL: ${{ secrets.TOKEN_URL }}
FORK_USER: ${{ secrets.FORK_USER }}
FORK_MAIL: ${{ secrets.FORK_MAIL }}
GITHUB_BUNDLED_REPO: ${{ secrets.GH_BUNDLED_REPO }}
GITHUB_SECURITY_ONLY_REPO: ${{ secrets.GH_SECURITY_ONLY_REPO }}
GITHUB_CONCURRENT_REPO: ${{ secrets.GH_CONCURRENT_REPO }}
GITLAB_ASSIGNEE_REPO: ${{ secrets.GITLAB_ASSIGNEE_REPO }}
GITHUB_REPO_ENV_REQUIRED: ${{ secrets.GH_REPO_ENV_REQUIRED }}
GITLAB_REPO_GITHUB_DEP: ${{ secrets.GITLAB_REPO_GITHUB_DEP }}
SELF_HOSTED_GITLAB_PERSONAL_ACCESS_TOKEN: ${{ steps.setup.outputs.pat }}
GITHUB_DEFAULT_BRANCH_IN_CONFIG: ${{ secrets.GH_DEFAULT_BRANCH_IN_CONFIG }}
GITHUB_PRIVATE_UPDATE_ALL_REPO: ${{ secrets.GH_PRIVATE_UPDATE_ALL_REPO }}
GITHUB_PRIVATE_INDIRECT_WITH_DIRECT: ${{ secrets.GH_PRIVATE_INDIRECT_WITH_DIRECT }}
GITLAB_SUPER_SECRET_URL_FOR_TOKEN: ${{ secrets.GITLAB_SUPER_SECRET_URL_FOR_TOKEN }}
VALID_CI_LICENCE: ${{ secrets.VALID_CI_LICENCE }}
BITBUCKET_APP_PASSWORD: ${{ secrets.BITBUCKET_APP_PASSWORD }}
BITBUCKET_WITH_PRIVATE_DEP: ${{ secrets.BITBUCKET_WITH_PRIVATE_DEP }}