-
Notifications
You must be signed in to change notification settings - Fork 4
146 lines (120 loc) · 4.59 KB
/
tests.yaml
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
name: Tests
on:
push:
branches:
- master
pull_request:
workflow_dispatch:
inputs:
IS_RELEASE:
required: true
type: boolean
VERSION:
required: true
env:
VERSIONS_LOCATION: "examples/resources/versions/"
jobs:
is-in-repo:
runs-on: ubuntu-latest
permissions: read-all
outputs:
isInRepo: ${{ steps.save-var.outputs.IS_IN_REPO }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Check for latest
id: save-var
run: |
if [[ -e "${{ env.VERSIONS_LOCATION }}${{ github.event.inputs.VERSION }}" ]]; then echo "IS_IN_REPO=true" >> $GITHUB_OUTPUT; else echo "IS_IN_REPO=false" >> $GITHUB_OUTPUT; fi
- name: Is latest in repo?
run: echo "${{ steps.save-var.outputs.IS_IN_REPO }}"
create-world:
runs-on: ubuntu-latest
permissions: write-all
needs:
- is-in-repo
if: ${{ github.event.inputs.VERSION != null && github.event.inputs.IS_RELEASE != null && needs.is-in-repo.outputs.isInRepo == 'false' }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
ref: master
- name: Get last version
run: echo "LAST_VERSION=$(curl -sSL "https://piston-meta.mojang.com/mc/game/version_manifest.json" | jq -cr '[.versions[] | select(.type == "release")] [1] .id')" >> $GITHUB_ENV
- name: Delete latest version folder
run: rm -rf ${{ env.VERSIONS_LOCATION }}latest
- name: Copy last version into latest folder
run: cp -R ${{ env.VERSIONS_LOCATION }}${{ env.LAST_VERSION }} ${{ env.VERSIONS_LOCATION }}latest
- name: Start server
run: docker run --name mc -e EULA=TRUE -e UID="$(id -u)" -e VERSION=${{ github.event.inputs.VERSION }} -e ENABLE_AUTOSTOP=TRUE -e AUTOSTOP_TIMEOUT_INIT=5 -e MEMORY=8G -v "$GITHUB_WORKSPACE"/${{ env.VERSIONS_LOCATION }}latest itzg/minecraft-server:latest --forceUpgrade
- name: Copy upgraded world into version folder
run: cp -R ${{ env.VERSIONS_LOCATION }}latest ${{ env.VERSIONS_LOCATION }}${{ github.event.inputs.VERSION }}
- if: ${{ github.event.inputs.IS_RELEASE == 'true' }}
name: Committing to master
uses: EndBug/add-and-commit@v9
with:
add: './${{ env.VERSIONS_LOCATION }}${{ github.event.inputs.VERSION }}/*'
message: 'add latest Minecraft world'
push: true
- if: ${{ github.event.inputs.IS_RELEASE == 'false' }}
name: Committing to snapshots
uses: EndBug/add-and-commit@v9
with:
add: './${{ env.VERSIONS_LOCATION }}${{ github.event.inputs.VERSION }}/*'
new_branch: snapshots
message: 'add latest Minecraft world'
push: true
tests:
runs-on: ubuntu-latest
needs:
- create-world
strategy:
matrix:
php-version: [ '8.0', '8.1', '8.2', '8.3' ]
name: Run tests on PHP v${{ matrix.php-version }}
if: always()
steps:
- if: ${{ github.event.inputs.IS_RELEASE == 'true' || github.event.inputs.IS_RELEASE == null }}
name: Checkout master
uses: actions/checkout@v4
with:
ref: master
- if: ${{ github.event.inputs.IS_RELEASE == 'false' }}
name: Checkout snapshots
uses: actions/checkout@v4
with:
ref: snapshots
- name: Show resource folder
run: tree ${{ env.VERSIONS_LOCATION }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
- name: Set composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Restore composer from cache
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Update composer
run: composer update
- name: Install composer dependencies
run: composer install --no-interaction --prefer-dist --no-progress
- name: Run phpunit tests
run: vendor/bin/phpunit --colors=always --testdox
delete-snapshot-branch:
runs-on: ubuntu-latest
permissions: write-all
needs:
- tests
if: ${{ always() && github.event.inputs.IS_RELEASE != null && github.event.inputs.IS_RELEASE == 'false' }}
steps:
- name: Checkout snapshots
uses: actions/checkout@v4
with:
ref: snapshots
- name: Delete snapshot branch
run: git push origin --delete snapshots