forked from chainguard-dev/malcontent
-
Notifications
You must be signed in to change notification settings - Fork 0
84 lines (72 loc) · 2.69 KB
/
version.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
72
73
74
75
76
77
78
79
80
81
82
83
84
name: Bump Version
on:
workflow_dispatch:
inputs:
update:
description: 'Semver update type (patch, minor, major)'
required: true
default: 'minor'
permissions:
contents: write
id-token: write
pull-requests: write
env:
VERSION_FILE: pkg/version/version.go
jobs:
version:
if: ${{ github.repository }} == 'chainguard-dev/bincapz'
runs-on: ubuntu-latest
steps:
- uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6
with:
egress-policy: audit
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
- uses: chainguard-dev/actions/setup-gitsign@e82b4e5ae10182af72972addcb3fedf7454621c8
- name: Update Version
id: update
run: |
UPDATE_TYPE=${{ github.event.inputs.update }}
CURRENT_VERSION=$(awk -F'"' '/ID string =/ {print $2}' ${{ env.VERSION_FILE }})
if [[ ! "${CURRENT_VERSION}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: CURRENT_VERSION is not a valid semver"
exit 1
fi
IFS='.' read -ra VERSION_PARTS <<< "${CURRENT_VERSION:1}"
case "$UPDATE_TYPE" in
major)
VERSION=$(printf "v%d.0.0" $((${VERSION_PARTS[0]}+1)))
;;
minor)
VERSION=$(printf "v%s.%d.0" ${VERSION_PARTS[0]} $((${VERSION_PARTS[1]}+1)))
;;
patch)
VERSION=$(printf "v%s.%s.%d" ${VERSION_PARTS[0]} ${VERSION_PARTS[1]} $((${VERSION_PARTS[2]}+1)))
;;
*)
echo "Error: Invalid update type"
exit 1
;;
esac
if [[ ! "${VERSION}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: VERSION is not a valid semver"
exit 1
fi
echo "Current bincapz version: $CURRENT_VERSION"
echo "New bincapz version: $VERSION"
sed -i -e "s/ID string = \"v[0-9]+\.[0-9]+\.[0-9]+\"/ID string = \"$VERSION\"/" ${{ env.VERSION_FILE }}
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
- name: Commit Version Update
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
VERSION=${{ steps.update.outputs.VERSION }}
BRANCH="bincapz-version-bump-$VERSION"
git checkout -b $BRANCH
git add ${{ env.VERSION_FILE }}
git commit -m "Bump bincapz version to $VERSION"
git push origin $BRANCH
- name: Create Pull Request
env:
GH_TOKEN: ${{ github.token }}
run: |
gh pr create -t "Update bincapz to $VERSION" -b "PR to update the version in ${{ env.VERSION_FILE }} to $VERSION" -B main