Skip to content

Commit edef7cb

Browse files
committed
add self-test
1 parent 6f41ffc commit edef7cb

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

.github/workflows/self-test.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Self Test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- action.yml
9+
- README.md
10+
- .github/workflows/self-test.yml
11+
pull_request:
12+
paths:
13+
- action.yml
14+
- README.md
15+
- .github/workflows/self-test.yml
16+
workflow_dispatch:
17+
18+
permissions:
19+
contents: read
20+
21+
jobs:
22+
integration:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Check out action source
26+
uses: actions/checkout@v4
27+
with:
28+
path: action-src
29+
30+
- name: Prepare local fixture repository
31+
shell: bash
32+
run: |
33+
set -euo pipefail
34+
35+
git init --bare remote.git
36+
37+
git init .
38+
git config user.email "ci@example.com"
39+
git config user.name "CI"
40+
git checkout -b main
41+
42+
mkdir -p reports
43+
echo "initial" > reports/report.html
44+
git add reports/report.html
45+
git commit -m "init fixture"
46+
47+
git remote add origin "$PWD/remote.git"
48+
git push -u origin main
49+
50+
git tag v-test
51+
git push origin v-test
52+
53+
# Simulate a dirty tracked file before the action runs (regression guard for #1).
54+
echo "dirty workspace" > reports/report.html
55+
56+
# Ensure explicit branch validation does not depend on local origin/* refs (guard for #2).
57+
git update-ref -d refs/remotes/origin/main || true
58+
59+
- name: Run action with explicit branch on dirty workspace
60+
uses: ./action-src
61+
with:
62+
coverage: "81.2%"
63+
branch: main
64+
report: reports/report.html
65+
66+
- name: Verify explicit branch run
67+
shell: bash
68+
run: |
69+
set -euo pipefail
70+
71+
test "$(cat reports/report.html)" = "dirty workspace"
72+
git --git-dir=remote.git rev-parse --verify refs/heads/coverage >/dev/null
73+
74+
files="$(git --git-dir=remote.git ls-tree --name-only -r coverage)"
75+
echo "$files" | rg "^main/badge.svg$"
76+
echo "$files" | rg "^main/report.html$"
77+
78+
- name: Run action in tag-triggered mode
79+
uses: ./action-src
80+
env:
81+
GITHUB_REF_TYPE: tag
82+
GITHUB_REF_NAME: v-test
83+
GITHUB_REF: refs/tags/v-test
84+
GITHUB_HEAD_REF: ""
85+
with:
86+
coverage: "82%"
87+
88+
- name: Verify tag-triggered run
89+
shell: bash
90+
run: |
91+
set -euo pipefail
92+
93+
git clone remote.git verify >/dev/null 2>&1
94+
pushd verify >/dev/null
95+
git checkout coverage
96+
test -f main/badge.svg
97+
test ! -f main/report.html
98+
popd >/dev/null

0 commit comments

Comments
 (0)