forked from bekriebel/balena-cli-action
-
-
Notifications
You must be signed in to change notification settings - Fork 3
87 lines (82 loc) · 3.23 KB
/
check-latest-release.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
name: Check if we're using the latest Balena CLI Version
on:
schedule:
- cron: "00 * * * *" # Run hourly
workflow_dispatch:
jobs:
main:
runs-on: ubuntu-20.04
steps:
- name: Check out repository
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- name: Get Latest Release
id: latest_version
uses: abatilo/[email protected]
with:
owner: balena-io
repo: balena-cli
- name: Perform check and update
env:
LATEST_CLI: ${{ steps.latest_version.outputs.latest_tag }}
run: |
GITHUB_BRANCH=$( echo "${{ github.ref }}" | sed 's/refs\/heads\///g' )
echo "LATEST_CLI=$LATEST_CLI" >> $GITHUB_ENV
echo "GITHUB_BRANCH=$GITHUB_BRANCH" >> $GITHUB_ENV
# Get the latest CLI release
if [ $LATEST_CLI == 'null' ]; then
echo "Latest release given as $LATEST_CLI. Quitting."
exit 0
fi
if grep -q "$LATEST_CLI" Dockerfile; then
echo "We're on the latest Balena CLI release $LATEST_CLI."
exit 0
else
echo "We're not on the latest Balena CLI release. Updating to $LATEST_CLI."
sed -i -E '13 s/BALENA_RELEASE=.*/BALENA_RELEASE="'$LATEST_CLI'" \&\& \\/g' Dockerfile
sed -i -E 's/uses: NebraLtd\/balena-cli-action@v[0-9]+\.[0-9]+\.[0-9]+/uses: NebraLtd\/balena-cli-action@'$LATEST_CLI'/g' README.md
UPDATED=true
echo "UPDATED=$UPDATED" >> $GITHUB_ENV
exit 0
fi
- name: Push updated Dockerfile if available
if: env.UPDATED == 'true'
id: push
uses: test-room-7/action-update-file@v1
with:
branch: ${{ env.GITHUB_BRANCH }}
file-path: |
Dockerfile
README.md
commit-msg: Update action to latest CLI ${{ env.LATEST_CLI }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Tag Commit
if: env.UPDATED == 'true'
uses: NebraLtd/git-tag-action@master
env:
TAG: ${{ env.LATEST_CLI }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_SHA: ${{ steps.push.outputs.commit-sha }}
- name: Release
if: env.UPDATED == 'true'
uses: ncipollo/release-action@v1
with:
allowUpdates: true
body: "Bump action to ${{ env.LATEST_CLI }}"
commit: ${{ steps.push.outputs.commit-sha }}
tag: ${{ env.LATEST_CLI }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Report Status
if: env.UPDATED == 'true'
uses: ravsamhq/notify-slack-action@master
with:
status: ${{ job.status }}
notification_title: 'Balena CLI Action has been updated to ${{ env.LATEST_CLI }}. Please publish release to GitHub Marketplace!'
message_format: '{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}>'
footer: '<{run_url}|View Run> | Linked Repo <{repo_url}|{repo}> | <{workflow_url}|View Workflow>'
mention_groups: 'S02GCFWL27R'
notify_when: 'success'
token: ${{ secrets.GITHUB_TOKEN }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.MINER_MONITORING_SLACK }}