Skip to content

Commit b718fda

Browse files
committed
Set up automatic releases
Signed-off-by: Bryan Richter <b@chreekat.net>
1 parent 4c75238 commit b718fda

3 files changed

Lines changed: 173 additions & 0 deletions

File tree

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
name: Monthly Release
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: "17 12 1 * *" # At 12:17 on day-of-month 1 (avoid top-of-hour load)
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
check:
14+
runs-on: ubuntu-latest
15+
if: ${{ github.repository == 'p4lang/p4runtime' && github.ref == 'refs/heads/main' }}
16+
outputs:
17+
has_commits: ${{ steps.check_commits.outputs.has_commits }}
18+
steps:
19+
- name: Check for new commits since latest tag
20+
id: check_commits
21+
env:
22+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
run: |
24+
REPO="${{ github.repository }}"
25+
TAG="$(gh api "repos/${REPO}/tags" --jq '.[0].name' 2>/dev/null || echo '')"
26+
if [ -z "$TAG" ]; then
27+
echo "No tags found, proceeding with release."
28+
echo "has_commits=true" >> $GITHUB_OUTPUT
29+
else
30+
AHEAD="$(gh api "repos/${REPO}/compare/${TAG}...main" --jq '.ahead_by')"
31+
if [ "$AHEAD" -eq 0 ]; then
32+
echo "No new commits since $TAG, skipping release."
33+
echo "has_commits=false" >> $GITHUB_OUTPUT
34+
else
35+
echo "$AHEAD new commits since $TAG."
36+
echo "has_commits=true" >> $GITHUB_OUTPUT
37+
fi
38+
fi
39+
40+
release-pr:
41+
needs: check
42+
if: needs.check.outputs.has_commits == 'true'
43+
runs-on: ubuntu-latest
44+
steps:
45+
- name: Checkout
46+
uses: actions/checkout@v6
47+
with:
48+
fetch-depth: 0
49+
50+
- name: Increment version number
51+
run: perl -i -pe 's/\b(\d+)(?=\D*$)/$1+1/e' VERSION
52+
53+
- name: Get changelog
54+
id: changelog
55+
run: |
56+
TAG="$(git describe --tags --abbrev=0 2>/dev/null || git rev-list --max-parents=0 HEAD)"
57+
GIT_LOG="$(git log $TAG..HEAD --oneline --pretty=format:"- %s [%an]")"
58+
CHANGELOG=$(cat << EOF
59+
Changelog:
60+
$GIT_LOG
61+
EOF
62+
)
63+
CHANGELOG="${CHANGELOG//'#'/''}"
64+
echo "content<<EOF" >> "$GITHUB_OUTPUT"
65+
echo "$CHANGELOG" >> "$GITHUB_OUTPUT"
66+
echo "EOF" >> "$GITHUB_OUTPUT"
67+
68+
- name: Display changelog
69+
run: |
70+
cat <<'EOF'
71+
${{ steps.changelog.outputs.content }}
72+
EOF
73+
74+
- name: Get version
75+
run: |
76+
VERSION="$(cat VERSION)"
77+
echo "VERSION=$VERSION" >> $GITHUB_ENV
78+
79+
- name: Get commit message
80+
id: message
81+
run: |
82+
COMMIT_MSG=$(cat << 'EOF'
83+
Release v${{ env.VERSION }}
84+
85+
${{ steps.changelog.outputs.content }}
86+
EOF
87+
)
88+
echo "content<<EOF" >> "$GITHUB_OUTPUT"
89+
echo "$COMMIT_MSG" >> "$GITHUB_OUTPUT"
90+
echo "EOF" >> "$GITHUB_OUTPUT"
91+
92+
- name: Get pull request body message
93+
id: body
94+
run: |
95+
MSG=$(cat << 'EOF'
96+
Auto-generated pull request for version ${{ env.VERSION }}.
97+
98+
Please use **Squash and merge** to include the changelog in the release message.
99+
100+
${{ steps.changelog.outputs.content }}
101+
EOF
102+
)
103+
echo "content<<EOF" >> "$GITHUB_OUTPUT"
104+
echo "$MSG" >> "$GITHUB_OUTPUT"
105+
echo "EOF" >> "$GITHUB_OUTPUT"
106+
107+
- name: Create Pull Request
108+
uses: peter-evans/create-pull-request@v8
109+
with:
110+
base: main
111+
add-paths: VERSION
112+
reviewers: antoninbas, jafingerhut, smolkaj
113+
commit-message: ${{ steps.message.outputs.content }}
114+
signoff: false
115+
branch: v${{ env.VERSION }}
116+
delete-branch: true
117+
title: Automated Release v${{ env.VERSION }}
118+
body: ${{ steps.body.outputs.content }}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Publish Release
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
paths:
9+
- "VERSION"
10+
11+
# Cancel any preceding run on the pull request.
12+
concurrency:
13+
group: release-${{ github.event.pull_request.number || github.ref }}
14+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
15+
16+
jobs:
17+
publish:
18+
if: ${{ github.repository == 'p4lang/p4runtime' }}
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: write
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v6
25+
with:
26+
fetch-depth: 0
27+
28+
- name: Get version
29+
run: |
30+
VERSION="$(cat VERSION)"
31+
TAG="v$(cat VERSION)"
32+
echo "VERSION=$VERSION" >> $GITHUB_ENV
33+
echo "TAG=$TAG" >> $GITHUB_ENV
34+
35+
- name: Check if tag exists
36+
id: check_tag
37+
run: |
38+
TAG="${{ env.TAG }}"
39+
if git rev-parse "$TAG" >/dev/null 2>&1; then
40+
echo "Tag $TAG already exists, skipping release creation."
41+
echo "tag_exists=true" >> $GITHUB_OUTPUT
42+
else
43+
echo "Tag $TAG does not exist."
44+
echo "tag_exists=false" >> $GITHUB_OUTPUT
45+
fi
46+
47+
- name: Release
48+
if: steps.check_tag.outputs.tag_exists == 'false'
49+
uses: softprops/action-gh-release@v2
50+
with:
51+
tag_name: ${{ env.TAG }}
52+
generate_release_notes: true
53+
env:
54+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.5.0

0 commit comments

Comments
 (0)