-
Notifications
You must be signed in to change notification settings - Fork 15
78 lines (72 loc) · 2.55 KB
/
readme-versions.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
name: README Versions
on:
pull_request:
types: [opened, reopened, synchronize]
branches: [main]
paths:
- Dockerfile
jobs:
readme:
name: Update README versions
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout PR
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Parse Caddy version
id: caddy
shell: bash
run: |
CADDY_VERSION=$(grep -m 1 -Eo 'caddy:[0-9]+\.[0-9]+\.[0-9]+' Dockerfile \
| sed -E 's/.+:([0-9]+\.[0-9]+\.[0-9]+)(.+)?$/\1/g')
MAJOR=$(echo "$CADDY_VERSION" | cut -d . -f 1)
MINOR=$(echo "$CADDY_VERSION" | cut -d . -f 2)
PATCH=$(echo "$CADDY_VERSION" | cut -d . -f 3)
cat <<EOF | tee -a "$GITHUB_OUTPUT"
version=$CADDY_VERSION
major=$MAJOR
minor=$MINOR
patch=$PATCH
EOF
- name: Update README
shell: bash
env:
VERSION: ${{ steps.caddy.outputs.version }}
MAJOR: ${{ steps.caddy.outputs.major }}
MINOR: ${{ steps.caddy.outputs.minor }}
PATCH: ${{ steps.caddy.outputs.patch }}
run: |
cat > tags.md <<EOF
- [\`latest\`]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/tree/v$VERSION)
- [\`$VERSION\`]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/tree/v$VERSION)
- [\`$MAJOR.$MINOR\`]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/tree/v$MAJOR.$MINOR)
- [\`$MAJOR\`]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/tree/v$MAJOR)
EOF
awk '
BEGIN{p=1}
$1=="<!--START-TAGS-->"{p=0;print;next}
$1=="<!--END-TAGS-->"{system("cat tags.md");p=1}
p
' README.md > README.md.new
mv README.md.new README.md
rm tags.md
- name: Check if README was updated
id: changed
shell: bash
run: |
if git diff-index --quiet HEAD ; then
echo "changed=false" | tee -a "$GITHUB_OUTPUT"
else
echo "changed=true" | tee -a "$GITHUB_OUTPUT"
fi
- name: Push changes back to PR
if: steps.changed.outputs.changed == 'true'
uses: iarekylew00t/verified-bot-commit@b736aa5032e8208bb405e273908a1b90f72c0d48 # v1.0.14
with:
ref: ${{ github.event.pull_request.head.ref }}
message: "docs: Updating README for v${{ steps.caddy.outputs.version }}"
files: |
README.md