-
Notifications
You must be signed in to change notification settings - Fork 23
72 lines (60 loc) · 2.54 KB
/
cron.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
---
name: Check Repo Updates
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * 0' # Check every Sunday
env:
IMAGES_DIR: "images"
jobs:
# Generate the values for the matrix where the updates are executed
generate-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.generate-matrix.outputs.matrix }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Generate Matrix Content
id: generate-matrix
run: |
IMAGES=$( ls -1 ${{ env.IMAGES_DIR }} | tr '\n' ',' | sed 's/[^,]\+/"\0"/g;s/,$//' )
echo "::set-output name=matrix::{ \"image\": [ ${IMAGES} ] }"
# ---
# Update the version of the existing images when possible and launch pull request
check-repo-updates:
needs: generate-matrix
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson( needs.generate-matrix.outputs.matrix ) }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set env vars
run: |
echo "IMAGE_DIR=./images/${{ matrix.image }}" >> $GITHUB_ENV
- name: Update Current Tag
id: update_tag
run: |
cd ${{ env.IMAGE_DIR }}
echo "::set-output name=old-version::$( sed -n '/IMAGE_TAG/s/^.*=//p' image_info.sh || echo 'NOT_FOUND' )"
[[ -f ./update_current_tag.sh ]] && ./update_current_tag.sh
echo "::set-output name=new-version::$( sed -n '/IMAGE_TAG/s/^.*=//p' image_info.sh || echo 'NOT_FOUND' )"
continue-on-error: true
# Launch Pull Request only when the version is updated
- name: Create Pull Request for ${{ matrix.image }}
if:
${{ steps.update_tag.outputs.old-version != steps.update_tag.outputs.new-version }}
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GRADIANT_BOT_TOKEN }}
base: main
body: |
This PR is auto-generated to automatically test and update version for image ${{ matrix.image }}
From -> ${{ matrix.image }}:${{ steps.update_tag.outputs.old-version }}
To -> ${{ matrix.image }}:${{ steps.update_tag.outputs.new-version }}
branch: ${{ matrix.image }}-version-update
commit-message: "Updating version ${{ matrix.image }} [${{ steps.update_tag.outputs.old-version }} -> ${{ steps.update_tag.outputs.new-version }}] "
delete-branch: true
title: "[${{ matrix.image }}] Update Version ${{ steps.update_tag.outputs.old-version }} -> ${{ steps.update_tag.outputs.new-version }}"
# ---