Skip to content

Commit cc7797d

Browse files
authored
Switch to Docker container action (#1)
This is to avoid messing with users' environments, and to make sure the action works in a clean environment.
1 parent 60680db commit cc7797d

14 files changed

+1536
-74
lines changed

.env

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
GITHUB_WORKSPACE=/github/workspace
2+
GITHUB_OUTPUT=/dev/stdout
3+
4+
INPUT_MODE=minor-only
5+
INPUT_SOURCE=offline

.gitattributes

-19
Original file line numberDiff line numberDiff line change
@@ -1,20 +1 @@
11
* text=auto eol=lf
2-
3-
/resources/all-versions.json -diff linguist-generated=true
4-
/tests/.pest/snapshots -diff linguist-generated=true
5-
/tests/data -diff linguist-generated=true
6-
7-
# Ignore everything.
8-
/* export-ignore
9-
10-
# Export white-listed production code only.
11-
/bin -export-ignore
12-
/resources -export-ignore
13-
/src -export-ignore
14-
/composer.json -export-ignore
15-
/composer.lock -export-ignore
16-
/LICENSE -export-ignore
17-
/README.md -export-ignore
18-
19-
# Ignore internal scripts.
20-
/bin/update-all-versions -export-ignore

.github/dependabot.yml

+10
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,13 @@ updates:
55
directory: /
66
schedule:
77
interval: weekly
8+
9+
- package-ecosystem: docker
10+
directory: /
11+
schedule:
12+
interval: weekly
13+
14+
- package-ecosystem: composer
15+
directory: /
16+
schedule:
17+
interval: weekly

.github/workflows/test.yml

+14-16
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ on:
88
push:
99
branches:
1010
- main
11+
tags:
12+
- '**'
1113
paths-ignore:
1214
- .gitattributes
1315
- .gitignore
@@ -23,8 +25,6 @@ permissions: {}
2325
jobs:
2426
positive:
2527
runs-on: ubuntu-latest
26-
permissions:
27-
contents: read
2828
strategy:
2929
matrix:
3030
mode:
@@ -44,25 +44,24 @@ jobs:
4444

4545
steps:
4646
- uses: actions/checkout@v4
47+
with:
48+
path: local-action
4749

4850
- name: Create fake composer.json
49-
run: cp testdata/${{ matrix.case }}.composer.json composer.json
51+
run: cp local-action/testdata/${{ matrix.case }}.composer.json composer.json
5052

51-
- name: Use local action
53+
- uses: ./local-action
5254
id: subject
53-
uses: ./
5455
with:
5556
mode: ${{ matrix.mode }}
5657
source: ${{ matrix.source }}
5758

5859
- run: echo '${{ steps.subject.outputs.matrix }}' > actual.json
5960

60-
- run: diff <(jq --sort-keys . actual.json) <(jq --sort-keys . testdata/${{ matrix.case }}.${{ matrix.mode }}.golden.json)
61+
- run: diff <(jq --sort-keys . actual.json) <(jq --sort-keys . local-action/testdata/${{ matrix.case }}.${{ matrix.mode }}.golden.json)
6162

6263
negative:
6364
runs-on: ubuntu-latest
64-
permissions:
65-
contents: read
6665
strategy:
6766
matrix:
6867
mode:
@@ -82,13 +81,14 @@ jobs:
8281

8382
steps:
8483
- uses: actions/checkout@v4
84+
with:
85+
path: local-action
8586

8687
- name: Create fake composer.json
87-
run: cp testdata/${{ matrix.case }}.composer.json composer.json
88+
run: cp local-action/testdata/${{ matrix.case }}.composer.json composer.json
8889

89-
- name: Use local action
90+
- uses: ./local-action
9091
id: subject
91-
uses: ./
9292
with:
9393
mode: ${{ matrix.mode }}
9494
source: ${{ matrix.source }}
@@ -100,8 +100,6 @@ jobs:
100100

101101
missing:
102102
runs-on: ubuntu-latest
103-
permissions:
104-
contents: read
105103
strategy:
106104
matrix:
107105
mode:
@@ -114,13 +112,14 @@ jobs:
114112

115113
steps:
116114
- uses: actions/checkout@v4
115+
with:
116+
path: local-action
117117

118118
- name: Ensure no composer.json
119119
run: rm -f composer.json
120120

121-
- name: Use local action
121+
- uses: ./local-action
122122
id: subject
123-
uses: ./
124123
with:
125124
mode: ${{ matrix.mode }}
126125
source: ${{ matrix.source }}
@@ -129,4 +128,3 @@ jobs:
129128
- name: Assert action failed
130129
if: steps.subject.outcome != 'failure'
131130
run: exit 1
132-

.gitignore

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
composer.phar
2-
composer.json
3-
composer.lock
4-
/vendor/
1+
/vendor

Dockerfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM php:8.4.1-cli-alpine
2+
3+
COPY --from=composer/composer:2.8.4-bin /composer /usr/local/bin/composer
4+
5+
COPY bin/decode-php-constraint /usr/local/bin/decode-php-constraint
6+
COPY composer.json composer.lock /app/
7+
8+
RUN composer install --prefer-dist --no-dev --optimize-autoloader --no-interaction --working-dir=/app \
9+
&& ln -s /app/vendor/bin/php-matrix /usr/local/bin/php-matrix \
10+
&& composer clear-cache --no-interaction \
11+
&& rm /usr/local/bin/composer
12+
13+
COPY entrypoint.sh /entrypoint.sh
14+
15+
ENTRYPOINT ["/entrypoint.sh"]

action.yml

+3-32
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,10 @@ inputs:
1515
description: Source of releases information
1616
default: auto
1717

18-
token:
19-
description: The token to install php-matrix via composer
20-
default: ${{ github.token }}
21-
2218
outputs:
2319
matrix:
24-
description: The php matrix
25-
value: ${{ steps.php-matrix.outputs.matrix }}
20+
description: The PHP version matrix
2621

2722
runs:
28-
using: composite
29-
steps:
30-
- uses: shivammathur/setup-php@v2
31-
with:
32-
php-version: '8.4'
33-
coverage: none
34-
tools: typisttech/php-matrix:0.1.x
35-
env:
36-
GITHUB_TOKEN: ${{ inputs.token }}
37-
38-
- name: Decode PHP constraint
39-
run: echo "CONSTRAINT=$(php decode-php-constraint.php)" >> "$GITHUB_ENV"
40-
shell: bash
41-
42-
- name: Run php-matrix
43-
id: php-matrix
44-
run: |
45-
{
46-
echo 'matrix<<EOF'
47-
php-matrix --mode="$MODE" --source="$SOURCE" "$CONSTRAINT"
48-
echo EOF
49-
} >> "$GITHUB_OUTPUT"
50-
env:
51-
MODE: ${{ inputs.mode }}
52-
SOURCE: ${{ inputs.source }}
53-
shell: bash
23+
using: docker
24+
image: Dockerfile

decode-php-constraint.php renamed to bin/decode-php-constraint

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env php
12
<?php
23

34
declare(strict_types=1);

composer.json

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "typisttech/php-matrix-action-action",
3+
"description": "TODO",
4+
"type": "project",
5+
"keywords": [
6+
"ci",
7+
"cli",
8+
"github-actions"
9+
],
10+
"homepage": "https://github.com/typisttech/php-matrix-action",
11+
"license": "MIT",
12+
"authors": [
13+
{
14+
"name": "Typist Tech",
15+
"homepage": "https://typist.tech"
16+
},
17+
{
18+
"name": "Tang Rufus",
19+
"email": "[email protected]",
20+
"homepage": "https://tangrufus.com",
21+
"role": "Developer"
22+
}
23+
],
24+
"support": {
25+
"issues": "https://github.com/typisttech/php-matrix-action/issues",
26+
"source": "https://github.com/typisttech/php-matrix-action"
27+
},
28+
"require": {
29+
"typisttech/php-matrix": "^0.1.1"
30+
},
31+
"config": {
32+
"sort-packages": true
33+
},
34+
"bin": [
35+
"bin/decode-php-constraint"
36+
]
37+
}

0 commit comments

Comments
 (0)