-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.yml
86 lines (68 loc) · 2.55 KB
/
action.yml
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
name: "Package RPi image"
description: "Packages an RPi image as a zip, generates a .md5 and .sha256 files for image and zip"
inputs:
image_path:
description: "The path to the image file"
required: true
outputs:
image_name:
description: "The name of the image"
value: "${{ steps.package-image.outputs.image }}"
image_sha256:
description: "The SHA256 sum of the image"
value: "${{ steps.package-image.outputs.image_sha256 }}"
image_size:
description: "The size of the image in bytes"
value: "${{ steps.package-image.outputs.image_size }}"
zip_name:
description: "The name of the packaged image zip"
value: "${{ steps.package-image.outputs.zip_name }}"
zip_path:
description: "The path of the package image zip"
value: "${{ steps.package-image.outputs.zip_path }}"
zip_sha256:
description: "The SHA256 sum of the packaged image zip"
value: "${{ steps.package-image.outputs.zip_sha256 }}"
zip_size:
description: "The size of the packaged image zip in bytes"
value: "${{ steps.package-image.outputs.zip_size }}"
runs:
using: "composite"
steps:
- name: "📦 Package image"
id: package-image
run: |
IMAGE_PATH="${{ inputs.image_path }}"
FOLDER=$(dirname "$IMAGE_PATH")
IMAGE=$(basename "$IMAGE_PATH")
ZIP="${IMAGE%.*}.zip"
ZIP_PATH="${IMAGE_PATH%.*}.zip"
cd $FOLDER
# md5, sha256 and size of the image
echo "Calculating checksums of $IMAGE..."
md5sum $IMAGE > $IMAGE.md5
sha256sum $IMAGE > $IMAGE.sha256
IMAGE_SHA256=`cat $IMAGE.sha256 | cut -d ' ' -f 1`
IMAGE_SIZE=`stat -c %s $IMAGE`
echo "IMAGE_SHA256: $IMAGE_SHA256"
echo "IMAGE_SIZE: $IMAGE_SIZE"
# zip the image
echo "Zipping $IMAGE to $ZIP..."
zip $ZIP $IMAGE
# md5, sha256 and size of the zip
echo "Calculating checksums of $ZIP..."
md5sum $ZIP > $ZIP.md5
sha256sum $ZIP > $ZIP.sha256
ZIP_SHA256=`cat $ZIP.sha256 | cut -d ' ' -f 1`
ZIP_SIZE=`stat -c %s $ZIP`
echo "ZIP_SHA256: $ZIP_SHA256"
echo "ZIP_SIZE: $ZIP_SIZE"
# outputs
echo "image_name=$IMAGE" >> $GITHUB_OUTPUT
echo "image_sha256=$IMAGE_SHA256" >> $GITHUB_OUTPUT
echo "image_size=$IMAGE_SIZE" >> $GITHUB_OUTPUT
echo "zip_name=$ZIP" >> $GITHUB_OUTPUT
echo "zip_path=$ZIP_PATH" >> $GITHUB_OUTPUT
echo "zip_sha256=$ZIP_SHA256" >> $GITHUB_OUTPUT
echo "zip_size=$ZIP_SIZE" >> $GITHUB_OUTPUT
shell: bash