Repository navigation
138 lines (121 loc) · 4.62 KB
/
Copy pathcheck-upstream.yml
File metadata and controls
138 lines (121 loc) · 4.62 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: Check upstream HAProxy release
on:
schedule:
- cron: '35 2 * * *'
workflow_dispatch:
inputs:
upstream_repo:
description: 'Upstream GitHub repo (owner/name)'
required: false
default: 'haproxy/haproxy'
build_workflow:
description: 'Workflow file to trigger on new release'
required: false
default: 'build-haproxy-fips.yml'
stable_only:
description: 'Only consider stable releases? Set to "no" to include dev/rc tags'
required: false
default: 'yes'
permissions:
actions: write
contents: write
pull-requests: write
env:
UPSTREAM_REPO: ${{ inputs.upstream_repo || 'haproxy/haproxy' }}
BUILD_WORKFLOW: ${{ inputs.build_workflow || 'build-haproxy-fips.yml' }}
STABLE_ONLY: ${{ inputs.stable_only || 'yes' }}
jobs:
check:
runs-on: ubuntu-24.04
outputs:
new_version: ${{ steps.compare.outputs.new_version }}
steps:
- name: Fetch latest upstream release
id: upstream
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
latest=$(gh release view --repo "${UPSTREAM_REPO}" --json tagName -q '.tagName | ltrimstr("v")' 2>/dev/null || true)
if [ -z "${latest}" ]; then
if [ "${STABLE_ONLY}" = "yes" ]; then
latest=$(gh api repos/${UPSTREAM_REPO}/tags --jq '[.[].name | select(test("^v[0-9]+\\.[0-9]+\\.[0-9]+$"))] | .[0] | ltrimstr("v")')
else
latest=$(gh api repos/${UPSTREAM_REPO}/tags --jq '.[0].name | ltrimstr("v")')
fi
fi
echo "version=${latest}" >> "$GITHUB_OUTPUT"
- name: Fetch last built version
id: last_built
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
last=$(gh api repos/${{ github.repository }}/tags --jq '.[0].name | ltrimstr("v")')
echo "version=${last}" >> "$GITHUB_OUTPUT"
- name: Compare versions
id: compare
run: |
latest="${{ steps.upstream.outputs.version }}"
last="${{ steps.last_built.outputs.version }}"
echo "Upstream latest : ${latest}"
echo "Last built : ${last}"
if [ -z "${latest}" ]; then
echo "Could not determine upstream version; aborting." >&2
exit 1
fi
if [ "${latest}" = "${last}" ]; then
echo "Already up-to-date (${latest}); nothing to do."
echo "new_version=" >> "$GITHUB_OUTPUT"
else
echo "New release detected: ${latest} (previously ${last})"
echo "new_version=${latest}" >> "$GITHUB_OUTPUT"
fi
build:
needs: check
if: needs.check.outputs.new_version != ''
uses: ./.github/workflows/build-haproxy-fips.yml
with:
version: ${{ needs.check.outputs.new_version }}
permissions:
packages: write
contents: write
id-token: write
attestations: write
open-pr:
runs-on: ubuntu-24.04
needs: [check, build]
if: needs.check.outputs.new_version != ''
steps:
- uses: actions/checkout@v4
- name: Create release PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ needs.check.outputs.new_version }}
run: |
BRANCH="release/v${VERSION}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
if git ls-remote --exit-code origin "refs/heads/${BRANCH}" >/dev/null 2>&1; then
git fetch origin "${BRANCH}"
git checkout -b "${BRANCH}" "origin/${BRANCH}"
else
git checkout -b "${BRANCH}"
fi
sed -i 's|^VERSION="${VERSION:-[^}]*}"|VERSION="${VERSION:-'"${VERSION}"'}"|' \
build-haproxy-fips.sh
git add build-haproxy-fips.sh
git diff --cached --quiet && echo "Nothing to commit" || \
git commit -m "chore: bump default version to ${VERSION}"
git push --force-with-lease origin "${BRANCH}"
OPEN_PR=$(gh pr list --repo "${{ github.repository }}" \
--head "${BRANCH}" --state open --json number --jq '.[0].number')
if [ -z "${OPEN_PR}" ]; then
gh pr create \
--repo "${{ github.repository }}" \
--base main \
--head "${BRANCH}" \
--title "Release v${VERSION}" \
--body "Automated release PR for upstream version **${VERSION}**.
Merge this PR to record the new version as the repository default."
else
echo "Open PR #${OPEN_PR} for ${BRANCH} already exists; skipping gh pr create."
fi