-
Notifications
You must be signed in to change notification settings - Fork 3
84 lines (68 loc) · 2.78 KB
/
schedule.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
name: update-version
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *' # Midnight - every night
jobs:
get_version:
runs-on: ubuntu-latest
name: Get next GITHUB_CLI_VERSION
# https://stackoverflow.com/a/61236803
outputs:
gh_version: ${{ steps.gh_version.outputs.gh_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Get next gh version
id: gh_version
run: |
current_version="$(grep -Eo "ENV GITHUB_CLI_VERSION .+" debian/Dockerfile | cut -d' ' -f3)"
echo "$current_version"
latest_versions="$(curl -sL https://api.github.com/repos/cli/cli/releases | jq -c '.[] | select(.prerelease == false)' | jq -r '.tag_name' | tr '\n' ' ')"
echo "$latest_versions"
next_version="$(echo "$latest_versions" | grep -Eo "(.*?) v$current_version( |$)" | awk '{print $(NF-1)}' | cut -c2-)"
echo "$next_version"
echo "gh_version=${next_version}" >> $GITHUB_OUTPUT
update:
runs-on: ubuntu-latest
name: Update GITHUB_CLI_VERSION
needs: get_version
if: ${{ needs.get_version.outputs.gh_version != '' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Write gh version to env
run: |
echo "gh_version=${{needs.get_version.outputs.gh_version}}" >> $GITHUB_ENV
- name: Update GITHUB_CLI_VERSION
run: |
echo "${{ env.gh_version }}" | grep -Pq "^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"
find . -name Dockerfile -print0 | xargs -0 sed -i -E "s/^(ENV GITHUB_CLI_VERSION\s*).*$/\1${{ env.gh_version }}/g"
- name: Login to GitHub Container Registry
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Commit changes
uses: stefanzweifel/[email protected]
id: "commit"
with:
commit_message: "Update GITHUB_CLI_VERSION to ${{ env.gh_version }}"
commit_user_name: actions-user
commit_user_email: [email protected]
commit_author: GitHub Actions <[email protected]>
- name: Push Docker Image
if: steps.commit.outputs.changes_detected == 'true'
uses: docker/[email protected]
with:
push: true
context: .
file: ./debian/Dockerfile
tags: |
ghcr.io/${{ github.repository }}:${{ env.gh_version }}
ghcr.io/${{ github.repository }}:latest