Skip to content

Commit 823f96f

Browse files
committed
feat: Upload signed test PDFs as artifacts and refine PDF validation workflow.
1 parent 6b5c90c commit 823f96f

3 files changed

Lines changed: 70 additions & 74 deletions

File tree

.github/workflows/go.yml

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,34 @@ permissions:
1010
contents: read
1111

1212
jobs:
13-
1413
build:
1514
name: Build
1615
runs-on: ubuntu-latest
1716
steps:
18-
19-
- name: Set up Go 1.x
20-
uses: actions/setup-go@v5
21-
with:
22-
go-version: ^1.20
23-
24-
- name: Check out code into the Go module directory
25-
uses: actions/checkout@v4
26-
27-
- name: Build
28-
run: go build -v ./...
29-
30-
- name: Test
31-
run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
32-
33-
- name: Upload coverage report
34-
uses: codecov/codecov-action@v4
35-
with:
36-
file: ./coverage.txt
37-
flags: unittests
38-
name: codecov-umbrella
17+
- name: Set up Go 1.x
18+
uses: actions/setup-go@v5
19+
with:
20+
go-version: ^1.23
21+
22+
- name: Check out code into the Go module directory
23+
uses: actions/checkout@v4
24+
25+
- name: Build
26+
run: go build -v ./...
27+
28+
- name: Test
29+
run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
30+
31+
- name: Upload test PDF files
32+
uses: actions/upload-artifact@v6
33+
with:
34+
name: test-pdf-artifacts
35+
path: testfiles/success/
36+
retention-days: 7
37+
38+
- name: Upload coverage report
39+
uses: codecov/codecov-action@v4
40+
with:
41+
file: ./coverage.txt
42+
flags: unittests
43+
name: codecov-umbrella

.github/workflows/validation.yml

Lines changed: 22 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ permissions:
1414

1515
jobs:
1616
validation:
17+
name: PDF Validation
1718
runs-on: ubuntu-latest
19+
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
1820
steps:
1921
- name: Set up Go 1.x
2022
uses: actions/setup-go@v5
@@ -30,69 +32,57 @@ jobs:
3032
github-token: ${{ secrets.GITHUB_TOKEN }}
3133
name: test-pdf-artifacts
3234
path: test_pdf_files
35+
run-id: ${{ github.event.workflow_run.id }}
3336

3437
- name: Check for PDF files
3538
id: check_files
3639
run: |
3740
if [ -d "test_pdf_files" ] && [ -n "$(ls -A test_pdf_files 2>/dev/null)" ]; then
3841
echo "exists=true" >> $GITHUB_OUTPUT
39-
echo "Files found."
4042
else
4143
echo "exists=false" >> $GITHUB_OUTPUT
42-
echo "No files found."
4344
fi
4445
4546
- name: Run pdfcpu validation
4647
id: pdfcpu-validate
4748
if: steps.check_files.outputs.exists == 'true'
4849
run: |
49-
echo "::group::PDF pdfcpu Validation Results"
50-
# Create a temporary file to store validation results
5150
PDFCPU_RESULT_FILE=$(mktemp)
51+
VALIDATION_REPORT="validation_results.md"
52+
VALIDATION_PASSED="true"
5253
5354
{
5455
echo "## PDF Validation Results"
5556
echo ""
56-
5757
for file in test_pdf_files/*; do
58-
echo "### Validating $file with pdfcpu"
58+
echo "### Validating \`$(basename $file)\`"
5959
echo '```'
60-
61-
# pdfcpu validation
62-
pdfcpu validate -mode strict "$file" 2>&1 | tee -a $PDFCPU_RESULT_FILE
63-
PDFCPU_STATUS=$?
64-
65-
if [ $PDFCPU_STATUS -eq 0 ]; then
66-
echo "✅ pdfcpu validation passed for $file" | tee -a $PDFCPU_RESULT_FILE
60+
if pdfcpu validate -mode strict "$file" 2>&1; then
61+
echo "✅ Passed"
6762
else
68-
echo "❌ pdfcpu validation failed for $file" | tee -a $PDFCPU_RESULT_FILE
63+
echo "❌ Failed"
64+
VALIDATION_PASSED="false"
6965
fi
7066
echo '```'
71-
echo "" | tee -a $PDFCPU_RESULT_FILE
67+
echo ""
7268
done
73-
74-
# Determine pdfcpu status
75-
if grep -q "❌" $PDFCPU_RESULT_FILE; then
76-
echo "### ❌ Some pdfcpu validations failed"
77-
echo "See details above for specific failures."
78-
VALIDATION_PASSED="false"
69+
70+
if [ "$VALIDATION_PASSED" == "true" ]; then
71+
echo "### ✅ All validations passed"
7972
else
80-
echo "### ✅ All pdfcpu validations passed"
81-
VALIDATION_PASSED="true"
73+
echo "### ❌ Some validations failed"
8274
fi
83-
echo "validation_passed=$VALIDATION_PASSED" >> $GITHUB_OUTPUT
84-
} > validation_results.md
75+
} > $VALIDATION_REPORT
8576
86-
cat validation_results.md
87-
echo "::endgroup::"
77+
cat $VALIDATION_REPORT
78+
echo "validation_passed=$VALIDATION_PASSED" >> $GITHUB_OUTPUT
8879
8980
- name: Create skipped report
9081
if: steps.check_files.outputs.exists != 'true'
9182
run: |
9283
echo "## PDF Validation Results" > validation_results.md
9384
echo "" >> validation_results.md
94-
echo "### ⏭️ Validation Skipped: No PDF files found to validate" >> validation_results.md
95-
echo "validation_passed=skipped" >> $GITHUB_OUTPUT
85+
echo "### ⏭️ Skipped: No PDF files found" >> validation_results.md
9686
9787
- name: Upload validation results
9888
uses: actions/upload-artifact@v4
@@ -101,27 +91,10 @@ jobs:
10191
path: validation_results.md
10292
retention-days: 7
10393

104-
- name: Find PR comment
105-
if: github.event_name == 'pull_request'
106-
id: find-comment
107-
uses: peter-evans/find-comment@v4
108-
with:
109-
issue-number: ${{ github.event.pull_request.number }}
110-
comment-author: "github-actions[bot]"
111-
body-includes: "## PDF Validation Results"
112-
113-
- name: Create or update comment
114-
if: github.event_name == 'pull_request'
115-
uses: peter-evans/create-or-update-comment@v5
116-
with:
117-
comment-id: ${{ steps.find-comment.outputs.comment-id }}
118-
issue-number: ${{ github.event.pull_request.number }}
119-
body-file: validation_results.md
120-
edit-mode: replace
121-
12294
- name: Check validation status
95+
if: steps.check_files.outputs.exists == 'true'
12396
run: |
12497
if [[ "${{ steps.pdfcpu-validate.outputs.validation_passed }}" == "false" ]]; then
125-
echo "Validation failed! Check the PR comment for details."
98+
echo "Validation failed!"
12699
exit 1
127-
fi
100+
fi

sign/sign_test.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ func TestReaderCanReadPDF(t *testing.T) {
128128
func TestSignPDF(t *testing.T) {
129129
_ = os.RemoveAll("../testfiles/failed/")
130130
_ = os.MkdirAll("../testfiles/failed/", 0o777)
131+
_ = os.RemoveAll("../testfiles/success/")
132+
_ = os.MkdirAll("../testfiles/success/", 0o777)
131133

132134
files, err := os.ReadDir("../testfiles/")
133135
if err != nil {
@@ -143,13 +145,29 @@ func TestSignPDF(t *testing.T) {
143145
}
144146

145147
t.Run(f.Name(), func(st *testing.T) {
146-
outputFile, err := os.CreateTemp("", fmt.Sprintf("%s_%s_", t.Name(), f.Name()))
148+
var outputFile *os.File
149+
var err error
150+
151+
if st.Verbose() {
152+
// In verbose mode, write directly to the success directory in testfiles
153+
outputFile, err = os.Create(filepath.Join("../testfiles/success", f.Name()))
154+
} else {
155+
// In normal mode, use a temporary file
156+
outputFile, err = os.CreateTemp("", fmt.Sprintf("%s_%s_", t.Name(), f.Name()))
157+
}
158+
147159
if err != nil {
148160
st.Fatalf("%s", err.Error())
149161
}
162+
163+
// Only remove the file if we are NOT in verbose mode
150164
defer func() {
151-
if err := os.Remove(outputFile.Name()); err != nil {
152-
st.Errorf("Failed to remove output file: %v", err)
165+
if !st.Verbose() {
166+
if err := os.Remove(outputFile.Name()); err != nil {
167+
st.Errorf("Failed to remove output file: %v", err)
168+
}
169+
} else {
170+
st.Logf("Preserving test file in success folder: %s", outputFile.Name())
153171
}
154172
}()
155173

0 commit comments

Comments
 (0)