-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
97 lines (90 loc) · 3.31 KB
/
check_update.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
87
88
89
90
91
92
93
94
95
96
97
#
# Copyright (C) 2020-2024 Lin Song <[email protected]>
#
# This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
# Unported License: http://creativecommons.org/licenses/by-sa/3.0/
#
# Attribution required: please include my name in any derivative and let me
# know how you have improved it!
name: check_update
on:
workflow_call:
inputs:
os_type:
required: true
type: string
secrets:
CACHE_NAME:
required: true
outputs:
should_test:
value: ${{ jobs.check_update.outputs.should_test }}
should_update:
value: ${{ jobs.check_update.outputs.should_update }}
jobs:
check_update:
runs-on: ubuntu-22.04
if: github.repository_owner == 'hwdsl2'
env:
DOCKER_USER: ${{ github.repository_owner }}
OS_TYPE: ${{ inputs.os_type }}
outputs:
should_test: ${{ steps.check.outputs.should_test }}
should_update: ${{ steps.check.outputs.should_update }}
steps:
- name: Cache
uses: actions/cache@v4
with:
path: |
${{ runner.temp }}/.buildx-bin
${{ runner.temp }}/.buildx-cache
${{ runner.temp }}/.docker-images
key: ${{ secrets.CACHE_NAME }}-${{ github.sha }}-${{ github.run_id }}-check
restore-keys: |
${{ secrets.CACHE_NAME }}-
- name: Prepare
run: |
if [ "$OS_TYPE" = "alpine" ]; then
docker pull alpine:3.20
docker pull "$DOCKER_USER/ipsec-vpn-server"
elif [ "$OS_TYPE" = "debian" ]; then
docker pull debian:bookworm-slim
docker pull "$DOCKER_USER/ipsec-vpn-server:debian"
else
exit 1
fi
- name: Check
id: check
run: |
BASE_UPDATED=false
if [ "$OS_TYPE" = "alpine" ]; then
base_ts=$(docker inspect --format='{{.Created}}' alpine:3.20)
image_ts=$(docker inspect --format='{{.Created}}' "$DOCKER_USER/ipsec-vpn-server")
elif [ "$OS_TYPE" = "debian" ]; then
base_ts=$(docker inspect --format='{{.Created}}' debian:bookworm-slim)
image_ts=$(docker inspect --format='{{.Created}}' "$DOCKER_USER/ipsec-vpn-server:debian")
else
exit 1
fi
if [ -n "$base_ts" ] && [ -n "$image_ts" ]; then
base_ts_s=$(date -d "$base_ts" +%s)
image_ts_s=$(date -d "$image_ts" +%s)
ts_now=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
ts_now_s=$(date -d "$ts_now" +%s)
diff_s=$((ts_now_s - base_ts_s))
diff=$(printf '%dd %dh:%dm:%ds\n' $(($diff_s/86400)) $(($diff_s%86400/3600)) $(($diff_s%3600/60)) $(($diff_s%60)))
echo "Base update time: $base_ts"
echo "Image update time: $image_ts"
echo "Current time: $ts_now"
echo "Time diff (cur-base): $diff (${diff_s}s)"
if [ -n "$base_ts_s" ] && [ -n "$image_ts_s" ] \
&& [ "$base_ts_s" -ge "$image_ts_s" ] \
&& [ "$diff_s" -ge 14400 ]; then
echo "Starting build..."
BASE_UPDATED=true
else
echo "Not starting build."
fi
fi
echo "should_test=${BASE_UPDATED}" >> "$GITHUB_OUTPUT"
echo "should_update=${BASE_UPDATED}" >> "$GITHUB_OUTPUT"