forked from wso2/reference-implementations-afm
-
Notifications
You must be signed in to change notification settings - Fork 0
144 lines (129 loc) · 4.88 KB
/
release.yml
File metadata and controls
144 lines (129 loc) · 4.88 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
139
140
141
142
143
144
name: Release
on:
workflow_dispatch:
inputs:
implementation:
description: 'Implementation to release'
required: true
type: choice
options:
- ballerina-interpreter
- langchain-interpreter
branch:
description: 'Branch to release from'
required: false
default: 'main'
type: string
concurrency:
group: release-${{ github.event.inputs.implementation }}
cancel-in-progress: false
jobs:
validate:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
release_version: ${{ steps.version.outputs.RELEASE_VERSION }}
next_version: ${{ steps.version.outputs.NEXT_VERSION }}
steps:
- name: Validate branch format
env:
BRANCH: ${{ inputs.branch }}
run: |
# Validate branch format (alphanumeric, dash, underscore, dot, slash)
if [[ ! "$BRANCH" =~ ^[a-zA-Z0-9._/-]+$ ]]; then
echo "::error::Invalid branch name: $BRANCH"
exit 1
fi
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
fetch-depth: 0
- name: Read and validate version
id: version
env:
IMPLEMENTATION: ${{ inputs.implementation }}
run: |
# Determine version file
if [ -f "$IMPLEMENTATION/Ballerina.toml" ]; then
VERSION_FILE="$IMPLEMENTATION/Ballerina.toml"
elif [ -f "$IMPLEMENTATION/pyproject.toml" ]; then
VERSION_FILE="$IMPLEMENTATION/pyproject.toml"
else
echo "::error::No version file found for implementation: $IMPLEMENTATION"
exit 1
fi
# Read version (first match is package version)
RELEASE_VERSION=$(grep '^version = ' "$VERSION_FILE" | head -1 | sed 's/version = "\(.*\)"/\1/')
# Validate version format
if [[ ! "$RELEASE_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::Version in $VERSION_FILE must be in format X.Y.Z, got: $RELEASE_VERSION"
exit 1
fi
# Parse for next patch bump
MAJOR=$(echo "$RELEASE_VERSION" | cut -d. -f1)
MINOR=$(echo "$RELEASE_VERSION" | cut -d. -f2)
PATCH=$(echo "$RELEASE_VERSION" | cut -d. -f3)
NEXT_VERSION="$MAJOR.$MINOR.$((PATCH + 1))"
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_OUTPUT
echo "NEXT_VERSION=$NEXT_VERSION" >> $GITHUB_OUTPUT
echo "Releasing $RELEASE_VERSION, next will be $NEXT_VERSION"
- name: Check tag doesn't already exist
env:
TAG: ${{ inputs.implementation }}-v${{ steps.version.outputs.RELEASE_VERSION }}
run: |
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "::error::Tag $TAG already exists. Use re-release workflow to overwrite."
exit 1
fi
- name: Check release branch doesn't already exist
env:
RELEASE_BRANCH: release-${{ inputs.implementation }}-${{ steps.version.outputs.RELEASE_VERSION }}
run: |
if git ls-remote --exit-code --heads origin "$RELEASE_BRANCH" >/dev/null 2>&1; then
echo "::error::Release branch $RELEASE_BRANCH already exists. Use re-release workflow to overwrite."
exit 1
fi
release:
needs: validate
uses: ./.github/workflows/release-common.yml
with:
implementation: ${{ inputs.implementation }}
version: ${{ needs.validate.outputs.release_version }}
branch: ${{ inputs.branch }}
update_latest: ${{ inputs.branch == 'main' || inputs.branch == 'dev' }}
is_rerelease: false
permissions:
contents: write
packages: write
security-events: write
bump-version:
needs: [validate, release]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
- name: Bump version to next
env:
BRANCH: ${{ inputs.branch }}
IMPLEMENTATION: ${{ inputs.implementation }}
NEXT_VERSION: ${{ needs.validate.outputs.next_version }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git pull origin "$BRANCH" --rebase
# Determine version file
if [ -f "$IMPLEMENTATION/Ballerina.toml" ]; then
VERSION_FILE="$IMPLEMENTATION/Ballerina.toml"
elif [ -f "$IMPLEMENTATION/pyproject.toml" ]; then
VERSION_FILE="$IMPLEMENTATION/pyproject.toml"
fi
sed -i "s/^version = \".*\"/version = \"$NEXT_VERSION\"/" "$VERSION_FILE"
git add "$VERSION_FILE"
git commit -m "Bump $IMPLEMENTATION version to $NEXT_VERSION"
git push origin "$BRANCH"