-
Notifications
You must be signed in to change notification settings - Fork 31
91 lines (74 loc) · 3.16 KB
/
ci.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
name: ci
on:
push:
schedule:
- cron: "0 0 * * *"
jobs:
main:
runs-on: ubuntu-latest
strategy:
matrix:
version:
- master
- release
steps:
- name: Install jq
run: sudo apt-get update && sudo apt-get install -y jq
- name: Check for new release
id: check_release
run: |
# Fetch the latest release information from the target repository
RESPONSE=$(curl --silent --fail "https://api.github.com/repos/gchq/CyberChef/releases/latest")
if [ $? -ne 0 ]; then
echo "Failed to fetch the latest release information."
exit 1
fi
# Extract the "published_at" field using jq
PUBLISHED_AT=$(echo "$RESPONSE" | jq -r '.published_at')
# Convert the published_at to Unix timestamp
PUBLISHED_TIMESTAMP=$(date -d "$PUBLISHED_AT" +%s)
# Get the current time and convert it to Unix timestamp
CURRENT_TIMESTAMP=$(date +%s)
# Calculate the difference in seconds
TIME_DIFF=$(expr "$CURRENT_TIMESTAMP" - "$PUBLISHED_TIMESTAMP")
# If the difference is less than 86400 seconds (24 hours), proceed with the next steps
if [ $TIME_DIFF -le 86400 ]; then
echo "New release detected. Proceeding with the next steps."
echo "proceed=true" >> $GITHUB_OUTPUT
else
echo "No new release in the last 24 hours."
echo "proceed=false" >> $GITHUB_OUTPUT
fi
- name: Set up QEMU
if: steps.check_release.outputs.proceed == 'true'
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
if: steps.check_release.outputs.proceed == 'true'
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
if: steps.check_release.outputs.proceed == 'true'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set version for master
if: matrix.version == 'master' && steps.check_release.outputs.proceed == 'true'
run: echo 'VERSION=master' >> $GITHUB_ENV
- name: Set tag for master
if: matrix.version == 'master' && steps.check_release.outputs.proceed == 'true'
run: echo "TAG=docker.io/mpepping/cyberchef:latest" >> $GITHUB_ENV
- name: Set version for release
if: matrix.version == 'release' && steps.check_release.outputs.proceed == 'true'
run: curl -s https://api.github.com/repos/gchq/CyberChef/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/VERSION=\1/' >> $GITHUB_ENV
- name: Set tag for release
if: matrix.version == 'release' && steps.check_release.outputs.proceed == 'true'
run: echo "TAG=docker.io/mpepping/cyberchef:${VERSION}" >> $GITHUB_ENV
- name: Build and push
if: steps.check_release.outputs.proceed == 'true'
timeout-minutes: 720
uses: docker/build-push-action@v6
with:
push: true
platforms: linux/amd64,linux/arm64
build-args: VERSION=${{ env.VERSION }}
tags: ${{ env.TAG }}