-
Notifications
You must be signed in to change notification settings - Fork 0
105 lines (98 loc) · 4.39 KB
/
Copy pathupdate-version.yml
File metadata and controls
105 lines (98 loc) · 4.39 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: Update Version
on:
schedule:
- cron: '0 8 * * *'
workflow_dispatch:
permissions:
contents: write
pull-requests: write
env:
DEPENDENCY_NAME: Samba
DOCKERFILE_PATH: samba/Dockerfile
DOCKERFILE_VERSION_KEY: SAMBA_VERSION
DOCKERFILE_OS_VERSION_KEY: ALPINE_VERSION
jobs:
update-version:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Configure Git user
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Get current version
id: get-current
run: |
get_version() { grep "ARG $1=" "$DOCKERFILE_PATH" | cut -d '=' -f2 | tr -d '[:space:]'; }
version="$(get_version "$DOCKERFILE_VERSION_KEY")"
os_version="$(get_version "$DOCKERFILE_OS_VERSION_KEY")"
echo "Current version: $version (os: $os_version)"
echo "version=$version" >> $GITHUB_OUTPUT
echo "os_version=$os_version" >> $GITHUB_OUTPUT
- name: Get latest version
id: get-latest
run: |
version="$(docker run --rm alpine sh -c "apk --no-cache --no-progress update >/dev/null && apk upgrade >/dev/null && apk search -v -e samba | tr ' ' '\n' | grep 'samba-' | cut -d'-' -f2-")"
if [ -z "$version" ]; then
echo "Failed to fetch latest version" >&2
exit 1
fi
# Retrieve OS version
os_version="$(docker run --rm alpine cat /etc/alpine-release)"
if [ -z "$os_version" ]; then
echo "Failed to fetch Alpine version" >&2
exit 1
fi
echo "Latest version: $version (os: $os_version)"
echo "version=$version" >> $GITHUB_OUTPUT
echo "os_version=$os_version" >> $GITHUB_OUTPUT
- name: Check if update is needed
id: check
run: |
if [ "${{ steps.get-latest.outputs.version }}" = "${{ steps.get-current.outputs.version }}" ] \
&& [ "${{ steps.get-latest.outputs.os_version }}" = "${{ steps.get-current.outputs.os_version }}" ]; then
echo "up_to_date=true" >> $GITHUB_OUTPUT
else
echo "up_to_date=false" >> $GITHUB_OUTPUT
fi
- name: Pull request metadata
if: steps.check.outputs.up_to_date == 'false'
id: pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
version="${{ steps.get-latest.outputs.version }}"
title="Update $DEPENDENCY_NAME to v$version (os: ${{ steps.get-latest.outputs.os_version }})"
prs=$(gh pr list --search "$title" --json title | jq length)
if [ "$prs" -gt 0 ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
echo "title=$title" >> $GITHUB_OUTPUT
echo "body=Bumps $DEPENDENCY_NAME to version $version" >> $GITHUB_OUTPUT
echo "head_branch=update/v$version" >> $GITHUB_OUTPUT
echo "base_branch=main" >> $GITHUB_OUTPUT
- name: Create Pull Request
if: steps.pr.outputs.exists == 'false' && steps.check.outputs.up_to_date == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
version="${{ steps.get-latest.outputs.version }}"
branch="${{ steps.pr.outputs.head_branch }}"
git checkout -b "$branch"
update_dockerfile_version() { sed -i "s|ARG $1=.*|ARG $1=$2|" "$DOCKERFILE_PATH"; }
update_dockerfile_version "$DOCKERFILE_VERSION_KEY" "$version"
update_dockerfile_version "$DOCKERFILE_OS_VERSION_KEY" "${{ steps.get-latest.outputs.os_version }}"
sed -i -E "s|-\s*\[\`[0-9]+\`,\s*\`[0-9.]+\`,\s*\`latest\` \(${DOCKERFILE_PATH}\)\]|- [\`$(echo "$version" | cut -d'.' -f1,1)\`, \`$(echo "$version" | cut -d'.' -f1,2)\`, \`latest\` (${DOCKERFILE_PATH})]|" README.md
git commit -am "Update version to $version"
git push origin "$branch"
gh pr create --title "${{ steps.pr.outputs.title }}" \
--body "${{ steps.pr.outputs.body }}" \
--base "${{ steps.pr.outputs.base_branch }}" --head "$branch"