Skip to content

Commit 46da7eb

Browse files
authored
Add an automated, monthly release workflow. (#233)
Signed-off-by: Anamika AggarwaL <anamikaagg18@gmail.com>
1 parent 05f46c3 commit 46da7eb

File tree

4 files changed

+194
-0
lines changed

4 files changed

+194
-0
lines changed

.github/release.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# .github/release.yml
2+
3+
changelog:
4+
exclude:
5+
labels:
6+
- ignore-for-release
7+
categories:
8+
- title: Breaking Changes
9+
labels:
10+
- breaking-change
11+
- title: Bug Fixes
12+
labels:
13+
- bug
14+
- title: Enhancements
15+
labels:
16+
- enhancement
17+
- title: Python Changes
18+
labels:
19+
- python
20+
- title: Dependencies
21+
labels:
22+
- dependencies
23+
- title: CI/Infrastructure
24+
labels:
25+
- github_actions
26+
- title: Other Changes
27+
labels:
28+
- "*"
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: Automated 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+
build:
14+
runs-on: ubuntu-latest
15+
# Check if the event is not triggered by a fork
16+
if: ${{ github.repository == 'p4lang/ptf' && github.ref == 'refs/heads/main' }}
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v6
20+
with:
21+
# Fetch all history for all branches and tags
22+
fetch-depth: 0
23+
24+
- name: Check for new commits
25+
id: check_commits
26+
run: |
27+
TAG="$(git describe --tags --abbrev=0 2>/dev/null || git rev-list --max-parents=0 HEAD)"
28+
COMMIT_COUNT="$(git rev-list $TAG..HEAD --count)"
29+
echo "count=$COMMIT_COUNT" >> $GITHUB_OUTPUT
30+
if [ "$COMMIT_COUNT" -eq 0 ]; then
31+
echo "No new commits since $TAG, skipping release."
32+
else
33+
echo "$COMMIT_COUNT new commits since $TAG."
34+
fi
35+
36+
- name: Increment version number
37+
if: steps.check_commits.outputs.count != '0'
38+
run: perl -i -pe 's/\b(\d+)(?=\D*$)/$1+1/e' Version.txt
39+
40+
- name: Get changelog
41+
if: steps.check_commits.outputs.count != '0'
42+
id: changelog
43+
run: |
44+
TAG="$(git describe --tags --abbrev=0 2>/dev/null || git rev-list --max-parents=0 HEAD)"
45+
GIT_LOG="$(git log $TAG..HEAD --oneline --pretty=format:"- %s [%an]")"
46+
CHANGELOG=$(cat << EOF
47+
Changelog:
48+
$GIT_LOG
49+
EOF
50+
)
51+
CHANGELOG="${CHANGELOG//'#'/''}"
52+
echo "content<<EOF" >> "$GITHUB_OUTPUT"
53+
echo "$CHANGELOG" >> "$GITHUB_OUTPUT"
54+
echo "EOF" >> "$GITHUB_OUTPUT"
55+
56+
- name: Display changelog
57+
if: steps.check_commits.outputs.count != '0'
58+
run: |
59+
cat <<'EOF'
60+
${{ steps.changelog.outputs.content }}
61+
EOF
62+
63+
- name: Get version
64+
if: steps.check_commits.outputs.count != '0'
65+
run: |
66+
VERSION="$(cat Version.txt)"
67+
echo "VERSION=$VERSION" >> $GITHUB_ENV
68+
69+
- name: Get commit message
70+
if: steps.check_commits.outputs.count != '0'
71+
id: message
72+
run: |
73+
COMMIT_MSG=$(cat << 'EOF'
74+
Release v${{ env.VERSION }}
75+
76+
${{ steps.changelog.outputs.content }}
77+
EOF
78+
)
79+
echo "content<<EOF" >> "$GITHUB_OUTPUT"
80+
echo "$COMMIT_MSG" >> "$GITHUB_OUTPUT"
81+
echo "EOF" >> "$GITHUB_OUTPUT"
82+
83+
- name: Get pull request body message
84+
if: steps.check_commits.outputs.count != '0'
85+
id: body
86+
run: |
87+
MSG=$(cat << 'EOF'
88+
Auto-generated pull request for version ${{ env.VERSION }}.
89+
90+
Please use **Squash and merge** to include the changelog in the release message.
91+
92+
${{ steps.changelog.outputs.content }}
93+
EOF
94+
)
95+
echo "content<<EOF" >> "$GITHUB_OUTPUT"
96+
echo "$MSG" >> "$GITHUB_OUTPUT"
97+
echo "EOF" >> "$GITHUB_OUTPUT"
98+
99+
- name: Create Pull Request
100+
if: steps.check_commits.outputs.count != '0'
101+
uses: peter-evans/create-pull-request@v8
102+
with:
103+
base: main
104+
add-paths: Version.txt
105+
reviewers: fruffy, jafingerhut
106+
commit-message: ${{ steps.message.outputs.content }}
107+
signoff: false
108+
branch: v${{ env.VERSION }}
109+
delete-branch: true
110+
title: Automated Release v${{ env.VERSION }}
111+
body: ${{ steps.body.outputs.content }}

.github/workflows/ci-release.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: GitHub Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "Version.txt"
9+
- ".github/workflows/ci-release.yml"
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+
build:
18+
if: ${{ github.repository == 'p4lang/ptf' }}
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.txt)"
31+
TAG="v$(cat Version.txt)"
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.txt

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

0 commit comments

Comments
 (0)