-
Notifications
You must be signed in to change notification settings - Fork 29
71 lines (59 loc) · 2.91 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
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: Check if new version exist
id: check
run: |
SDK_VERSION=$(curl --silent "https://api.github.com/repos/GoogleCloudPlatform/cloud-sdk-docker/tags" | tac | grep '"name":' | sed -E 's/.*"([^"]+)".*/\1/' | sort -V -r | head -n 1)
LATEST_VERSION=$(curl --silent "https://api.github.com/repos/actions-hub/gcloud/releases/latest" | tac | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
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: ncipollo/release-action@v1
with:
tag: ${{ steps.modify.outputs.tag }}
token: ${{ secrets.GH_TOKEN }}