-
Notifications
You must be signed in to change notification settings - Fork 29
86 lines (72 loc) · 2.95 KB
/
upgrader.yaml
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: SDK version upgrade
on:
schedule:
- cron: "0 */12 * * *"
jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
run: |
git config --global url."https://${{ secrets.GH_TOKEN }}:@github.com/".insteadOf "https://github.com/"
git clone https://github.com/actions-hub/gcloud .
- name: Checkout sdk latest
uses: exelban/watch-tag@master
with:
provider: docker
repository: google/cloud-sdk
env_name: SDK_VERSION
- name: Checkout gcloud action latest
uses: exelban/watch-tag@master
with:
repository: actions-hub/gcloud
env_name: LATEST_VERSION
- name: Check if new version exist
id: check
run: |
DOCKER_VERSION=$(cat $GITHUB_WORKSPACE/Dockerfile | grep "FROM google/cloud-sdk:" | sed -E 's/FROM google\/cloud-sdk://' | sed -E 's/-alpine//')
echo $SDK_VERSION
echo $LATEST_VERSION
echo $DOCKER_VERSION
if [ "$SDK_VERSION" != "$LATEST_VERSION" ]; then
if [ "$LATEST_VERSION" = "`echo -e "$SDK_VERSION\n$LATEST_VERSION" | sort -V | head -n1`" ]; then
if [ "$DOCKER_VERSION" == "$LATEST_VERSION" ]; then
echo "New version detected: $SDK_VERSION. Latest in this repo: $LATEST_VERSION. Updating..."
echo ::set-output name=exist::"yes"
echo ::set-env name=SDK_VERSION::$SDK_VERSION
echo ::set-env name=LATEST_VERSION::$LATEST_VERSION
else
echo ::error::"Tag version in Dockerfile ($DOCKER_VERSION) is not the same as the latest release ($LATEST_VERSION)."
exit 1
fi
else
echo ::set-output name=exist::"no"
fi
else
echo ::set-output name=exist::"no"
fi
- name: Modify Dockerfile
id: modify
if: steps.check.outputs.exist == 'yes'
run: |
git config --global url."https://${{ secrets.GH_TOKEN }}:@github.com/".insteadOf "https://github.com/"
git config --global user.name "Serhiy Mytrovtsiy"
git config --global user.email "mitrovtsiy@ukr.net"
git checkout master
FROM_LINE="FROM google\/cloud-sdk:$LATEST_VERSION-alpine"
TO_LINE="FROM google\/cloud-sdk:$SDK_VERSION-alpine"
sed -i "s/${FROM_LINE}/${TO_LINE}/" $GITHUB_WORKSPACE/Dockerfile
git add $GITHUB_WORKSPACE/Dockerfile
git commit -m "updated gcloud-sdk to $SDK_VERSION"
git push
echo ::set-output name=tag::$SDK_VERSION
- name: Create new release
if: steps.modify.outputs.tag != '0'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
tag_name: ${{ steps.modify.outputs.tag }}
release_name: ${{ steps.modify.outputs.tag }}
draft: false
prerelease: false