-
Notifications
You must be signed in to change notification settings - Fork 4
140 lines (115 loc) · 4.51 KB
/
Copy pathtest-save-docker-image.yml
File metadata and controls
140 lines (115 loc) · 4.51 KB
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
name: Test Save Docker Image Action
on:
push:
paths:
- 'save-docker-image/**'
pull_request:
paths:
- 'save-docker-image/**'
workflow_dispatch:
jobs:
test-save-docker-image:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Pull a test Docker image
run: docker pull nginx:alpine
- name: Test basic usage
id: test-basic
uses: ./save-docker-image
with:
image-name: 'nginx'
tag: 'alpine'
artifact-name: 'nginx-alpine-basic'
- name: Verify basic test output
run: |
echo "Saved path: ${{ steps.test-basic.outputs.saved-path }}"
echo "File size: ${{ steps.test-basic.outputs.file-size }}"
# Verify file exists
if [ ! -f "${{ steps.test-basic.outputs.saved-path }}" ]; then
echo "❌ Error: Saved file does not exist"
exit 1
fi
# Verify file is not empty
if [ ! -s "${{ steps.test-basic.outputs.saved-path }}" ]; then
echo "❌ Error: Saved file is empty"
exit 1
fi
echo "✅ Basic test passed"
- name: Test custom output path
id: test-custom
uses: ./save-docker-image
with:
image-name: 'nginx'
tag: 'alpine'
output-path: './custom/nginx-alpine.tar'
artifact-name: 'nginx-alpine-custom'
- name: Verify custom path test
run: |
echo "Custom saved path: ${{ steps.test-custom.outputs.saved-path }}"
# Verify custom file exists
if [ ! -f "${{ steps.test-custom.outputs.saved-path }}" ]; then
echo "❌ Error: Custom path file does not exist"
exit 1
fi
# Verify it's in the expected location
if [ "${{ steps.test-custom.outputs.saved-path }}" != "./custom/nginx-alpine.tar" ]; then
echo "❌ Error: File not saved to expected custom path"
exit 1
fi
echo "✅ Custom path test passed"
- name: Test loading saved image
run: |
# Remove the original image
docker rmi nginx:alpine
# Load from saved file
docker load -i ${{ steps.test-basic.outputs.saved-path }}
# Verify image is loaded
if ! docker images | grep -q "nginx.*alpine"; then
echo "❌ Error: Failed to load saved image"
exit 1
fi
echo "✅ Image loading test passed"
- name: Test artifact upload functionality
id: test-artifact
uses: ./save-docker-image
with:
image-name: 'nginx'
tag: 'alpine'
artifact-name: 'nginx-alpine-artifact'
artifact-retention-days: 1
- name: Test summary
run: |
echo "## Test Results 🧪" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ Basic usage test: PASSED" >> $GITHUB_STEP_SUMMARY
echo "✅ Custom output path test: PASSED" >> $GITHUB_STEP_SUMMARY
echo "✅ Image loading test: PASSED" >> $GITHUB_STEP_SUMMARY
echo "✅ Artifact upload test: PASSED" >> $GITHUB_STEP_SUMMARY
echo "✅ Disable artifact upload test: PASSED" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### File Details" >> $GITHUB_STEP_SUMMARY
echo "- Basic test file: \`${{ steps.test-basic.outputs.saved-path }}\` (${{ steps.test-basic.outputs.file-size }} bytes)" >> $GITHUB_STEP_SUMMARY
echo "- Custom path file: \`${{ steps.test-custom.outputs.saved-path }}\` (${{ steps.test-custom.outputs.file-size }} bytes)" >> $GITHUB_STEP_SUMMARY
echo "- Artifact test file: \`${{ steps.test-artifact.outputs.saved-path }}\` (${{ steps.test-artifact.outputs.file-size }} bytes)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
test-error-handling:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Test with non-existent image (should fail)
id: test-error
continue-on-error: true
uses: ./save-docker-image
with:
image-name: 'non-existent-image'
tag: 'non-existent-tag'
- name: Verify error handling
run: |
if [ "${{ steps.test-error.outcome }}" = "success" ]; then
echo "❌ Error: Action should have failed with non-existent image"
exit 1
fi
echo "✅ Error handling test passed - action correctly failed with non-existent image"