Skip to content

Commit b892eee

Browse files
authored
ci: Add release automation workflows and version management (valkey-io#94)
* ci: Add release automation workflows and version management - Add commit-version-changes action to automate version bumping and commits - Add create-version-pr action to create pull requests for version updates - Add setup-release-branches action to initialize release branch structure - Add test-pecl-package action to validate PECL package builds - Add update-version-files action to update version constants across files - Add validate-version action to ensure version consistency - Update publish-pecl.yml workflow to support manual version bumping with dry-run mode - Update test-pecl.yml and test-pie.yml workflows for improved CI/CD integration - Update php_valkey_glide.h and valkey_glide.c with version management support - Enable pull request triggers for version-related file changes to validate workflow changes - Add workflow_dispatch inputs for version, release-branch, and dry-run testing Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com> * ci: Update PECL publishing workflow and validation actions - Add prepare-version-bump job dependency to build-packages job for consistent version handling - Update build-packages job condition to support pull_request events alongside existing triggers - Modify checkout ref to use prepare-version-bump output for workflow_dispatch events - Add PREPARE_VERSION environment variable to version extraction logic with fallback chain - Add github-token input parameter to test-pecl-package action for API access - Add PHP setup step with required extensions (tokenizer, json, ctype, iconv, mbstring) - Add system dependencies installation for PECL testing (php-dev, build-essential, protobuf tools) - Add shared dependencies installation step using install-shared-dependencies action - Add cbindgen installation with caching support for Rust toolchain - Add sccache setup for cross-user Rust caching - Enhance validate-version action with expected-version input parameter - Add source input to validate-version action for tracking version origin - Improve version extraction logic to accept manual input with fallback to GitHub context - Add detailed error messages with current event and ref information for debugging Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com> * ci: Refactor workflow actions to use environment variables - Move GitHub context variables to env section in commit-version-changes action - Move GitHub context variables to env section in publish-pecl workflow - Move GitHub context variables to env section in setup-release-branches action - Move GitHub context variables to env section in test-pecl-package action - Move GitHub context variables to env section in update-version-files action - Move GitHub context variables to env section in validate-version action - Add conditional check to skip version validation for pull request events - Simplify source parameter in validate-version call for manual releases - Improve readability by using env variables instead of inline GitHub context references Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com> * fix lint Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com> * fix git commit and version version will be updated in the dry run and commit will happen. the push will be skipped Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com> * Extract PECL package building into reusable action - Create new build-pecl-package composite action for building PECL packages - Extract package creation logic from publish-pecl workflow into dedicated action - Add inputs for optional version parameter with fallback to package.xml - Add outputs for package file path and version information - Refactor publish-pecl workflow to use new build-pecl-package action - Update test-pecl-package action to use new build action Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com> * fix lint yaml Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com> * - Update grep pattern to match full path "/src/client_constructor_mock.c" for accuracy - Add fallback error message when tarball listing fails Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com> * - Remove verbose file verification logic for src/client_constructor_mock.c Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com> * - Add version update logic to package.xml when INPUT_VERSION is provided Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com> * - Change test version format from "-pr-test" suffix to "RC" (release candidate) for PECL compatibility Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com> * - Add protobuf-compiler package to apt-get install list in test workflow Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com> * - Install dependencies with --no-interaction flag for CI compatibility Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com> * - Remove `if: inputs.skip-package-creation != 'true'` condition from protobuf generation step Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com> * - Add `check-rc` step to validate if release tag matches RC pattern (-rc[0-9]+) Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com> --------- Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
1 parent 1928211 commit b892eee

12 files changed

Lines changed: 1242 additions & 453 deletions

File tree

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
name: "Build PECL Package"
2+
description: "Create PECL package tarball from source files"
3+
inputs:
4+
version:
5+
description: "Package version (optional, will extract from package.xml if not provided)"
6+
required: false
7+
8+
outputs:
9+
package-file:
10+
description: "Path to the created PECL package file"
11+
value: ${{ steps.create-package.outputs.package-file }}
12+
package-version:
13+
description: "Version of the created package"
14+
value: ${{ steps.create-package.outputs.package-version }}
15+
16+
runs:
17+
using: "composite"
18+
steps:
19+
- name: Generate submodule commit info
20+
shell: bash
21+
run: |
22+
echo "=== Generating submodule commit info ==="
23+
git submodule status | while read commit path extra; do
24+
# Remove leading - or + from commit hash
25+
clean_commit=$(echo "$commit" | sed 's/^[-+]//')
26+
echo "$path=$clean_commit" >> .submodule-commits
27+
done
28+
cat .submodule-commits
29+
30+
- name: Create PECL package
31+
id: create-package
32+
shell: bash
33+
env:
34+
INPUT_VERSION: ${{ inputs.version }}
35+
run: |
36+
# Determine version
37+
if [ -n "$INPUT_VERSION" ]; then
38+
VERSION="$INPUT_VERSION"
39+
echo "Using provided version: $VERSION"
40+
41+
# Update package.xml with the provided version
42+
echo "=== Updating package.xml with version ==="
43+
DATE=$(date +%Y-%m-%d)
44+
TIME=$(date +%H:%M:%S)
45+
46+
sed -i "0,/<release>[^<]*<\/release>/s/<release>[^<]*<\/release>/<release>$VERSION<\/release>/" package.xml
47+
sed -i "0,/<api>[^<]*<\/api>/s/<api>[^<]*<\/api>/<api>$VERSION<\/api>/" package.xml
48+
sed -i "0,/<date>[^<]*<\/date>/s/<date>[^<]*<\/date>/<date>$DATE<\/date>/" package.xml
49+
sed -i "0,/<time>[^<]*<\/time>/s/<time>[^<]*<\/time>/<time>$TIME<\/time>/" package.xml
50+
51+
echo "Updated package.xml version to: $VERSION"
52+
else
53+
VERSION=$(grep -o '<release>[^<]*</release>' package.xml | sed 's/<[^>]*>//g' | head -1)
54+
echo "Extracted version from package.xml: $VERSION"
55+
fi
56+
57+
PACKAGE_DIR="valkey_glide-$VERSION"
58+
PACKAGE_FILE="$PACKAGE_DIR.tgz"
59+
60+
echo "=== Creating PECL package for version $VERSION ==="
61+
62+
# Debug: Show Makefile.frag contents
63+
echo "=== DEBUG: Contents of Makefile.frag ==="
64+
cat Makefile.frag | head -50
65+
echo "=== END Makefile.frag (first 50 lines) ==="
66+
67+
# Create clean package directory
68+
mkdir -p "$PACKAGE_DIR"
69+
70+
# Copy files as specified in package.xml
71+
echo "=== Copying files according to package.xml ==="
72+
73+
# Root files
74+
cp config.m4 "$PACKAGE_DIR/"
75+
cp Makefile.frag "$PACKAGE_DIR/"
76+
cp .gitmodules "$PACKAGE_DIR/"
77+
cp .submodule-commits "$PACKAGE_DIR/"
78+
cp package.xml "$PACKAGE_DIR/"
79+
80+
# Copy all .c and .h files (exclude temp files with ~)
81+
echo "=== Copying .c and .h files ==="
82+
for file in *.c *.h; do
83+
if [[ -f "$file" && "$file" != *~ ]]; then
84+
echo "Copying $file"
85+
cp "$file" "$PACKAGE_DIR/"
86+
fi
87+
done
88+
89+
# Copy stub files (exclude temp files with ~)
90+
echo "=== Copying .stub.php files ==="
91+
for file in *.stub.php; do
92+
if [[ -f "$file" && "$file" != *~ ]]; then
93+
echo "Copying $file"
94+
cp "$file" "$PACKAGE_DIR/"
95+
fi
96+
done
97+
98+
# Copy src directory
99+
echo "=== Copying src directory ==="
100+
mkdir -p "$PACKAGE_DIR/src"
101+
if [ -f "src/client_constructor_mock.c" ]; then
102+
cp src/client_constructor_mock.c "$PACKAGE_DIR/src/"
103+
echo "Copied src/client_constructor_mock.c"
104+
else
105+
echo "ERROR: src/client_constructor_mock.c not found!"
106+
ls -la src/
107+
exit 1
108+
fi
109+
110+
if [ -f "src/client_constructor_mock.stub.php" ]; then
111+
cp src/client_constructor_mock.stub.php "$PACKAGE_DIR/src/"
112+
echo "Copied src/client_constructor_mock.stub.php"
113+
else
114+
echo "ERROR: src/client_constructor_mock.stub.php not found!"
115+
ls -la src/
116+
exit 1
117+
fi
118+
119+
# Copy utils directory
120+
echo "=== Copying utils directory ==="
121+
mkdir -p "$PACKAGE_DIR/utils"
122+
if [ -f "utils/remove_optional_from_proto.py" ]; then
123+
cp utils/remove_optional_from_proto.py "$PACKAGE_DIR/utils/"
124+
echo "Copied utils/remove_optional_from_proto.py"
125+
else
126+
echo "WARNING: utils/remove_optional_from_proto.py not found"
127+
fi
128+
129+
# Copy documentation files
130+
echo "=== Copying documentation files ==="
131+
cp README.md "$PACKAGE_DIR/"
132+
cp LICENSE "$PACKAGE_DIR/"
133+
134+
# Create empty valkey-glide directory with .gitkeep
135+
echo "=== Creating valkey-glide directory ==="
136+
mkdir -p "$PACKAGE_DIR/valkey-glide"
137+
touch "$PACKAGE_DIR/valkey-glide/.gitkeep"
138+
139+
# Validate package.xml
140+
echo "=== Validating package.xml ==="
141+
if ! command -v xmllint >/dev/null 2>&1; then
142+
echo "Installing xmllint..."
143+
sudo apt-get update && sudo apt-get install -y libxml2-utils
144+
fi
145+
xmllint --noout package.xml || exit 1
146+
147+
# Verify all required files are present
148+
echo "=== Verifying package contents ==="
149+
echo "Checking for required files in package:"
150+
151+
REQUIRED_FILES=(
152+
"config.m4"
153+
"Makefile.frag"
154+
"package.xml"
155+
"src/client_constructor_mock.c"
156+
"src/client_constructor_mock.stub.php"
157+
)
158+
159+
for file in "${REQUIRED_FILES[@]}"; do
160+
if [ -f "$PACKAGE_DIR/$file" ]; then
161+
echo "$file"
162+
else
163+
echo "$file - MISSING!"
164+
exit 1
165+
fi
166+
done
167+
168+
# Create tarball
169+
echo "=== Creating tarball ==="
170+
tar czf "$PACKAGE_FILE" "$PACKAGE_DIR"
171+
172+
echo "=== PECL package created successfully ==="
173+
ls -la "$PACKAGE_FILE"
174+
175+
# Show package contents for verification
176+
echo "=== Package contents (first 30 files) ==="
177+
tar tzf "$PACKAGE_FILE" 2>/dev/null | head -30 || echo "Package contents listed successfully"
178+
179+
echo "=== PECL package creation completed successfully ==="
180+
181+
# Set outputs
182+
echo "package-file=$PACKAGE_FILE" >> $GITHUB_OUTPUT
183+
echo "package-version=$VERSION" >> $GITHUB_OUTPUT
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: "Commit Version Changes"
2+
description: "Commit and push version changes to branch"
3+
inputs:
4+
version:
5+
description: "Version being updated"
6+
required: true
7+
temp-branch:
8+
description: "Temporary branch to push to"
9+
required: true
10+
dry-run:
11+
description: "Dry run mode - show what would be committed without pushing"
12+
required: false
13+
default: "false"
14+
15+
runs:
16+
using: "composite"
17+
steps:
18+
- name: Commit and push changes
19+
shell: bash
20+
env:
21+
VERSION: ${{ inputs.version }}
22+
TEMP_BRANCH: ${{ inputs.temp-branch }}
23+
DRY_RUN: ${{ inputs.dry-run }}
24+
run: |
25+
COMMIT_MSG="chore: bump version to $VERSION
26+
27+
- Update VALKEY_GLIDE_PHP_VERSION in common.h
28+
- Update release and API versions in package.xml
29+
- Update date and time in package.xml
30+
31+
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
32+
33+
# Add files to staging
34+
git add common.h package.xml
35+
36+
# Check if there are changes to commit
37+
if git diff --cached --quiet; then
38+
echo "No changes to commit"
39+
exit 0
40+
fi
41+
42+
# Show what files will be committed
43+
echo "Files to be committed:"
44+
git diff --cached --name-only
45+
46+
if [ "$DRY_RUN" = "true" ]; then
47+
echo "DRY RUN: Committing locally but not pushing"
48+
echo "Branch: $TEMP_BRANCH"
49+
echo "Commit message:"
50+
echo "$COMMIT_MSG"
51+
52+
# Commit locally but don't push
53+
git commit -m "$COMMIT_MSG"
54+
echo "Local commit created successfully (not pushed in dry-run mode)"
55+
else
56+
echo "Committing and pushing version changes"
57+
echo "Branch: $TEMP_BRANCH"
58+
59+
git commit -m "$COMMIT_MSG"
60+
git push origin "$TEMP_BRANCH"
61+
echo "Changes committed and pushed successfully"
62+
fi
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: "Create Version PR"
2+
description: "Create pull request for version bump"
3+
inputs:
4+
version:
5+
description: "Version being updated"
6+
required: true
7+
temp-branch:
8+
description: "Source branch for PR"
9+
required: true
10+
target-branch:
11+
description: "Target branch for PR"
12+
required: true
13+
dry-run:
14+
description: "Dry run mode - show what PR would be created"
15+
required: false
16+
default: "false"
17+
github-token:
18+
description: "GitHub token for API access"
19+
required: true
20+
21+
outputs:
22+
pr-number:
23+
description: "Pull request number (999 for dry run)"
24+
value: ${{ steps.create-pr.outputs.pr-number }}
25+
26+
runs:
27+
using: "composite"
28+
steps:
29+
- name: Create Pull Request
30+
id: create-pr
31+
uses: actions/github-script@v7
32+
with:
33+
github-token: ${{ inputs.github-token }}
34+
script: |
35+
const version = '${{ inputs.version }}';
36+
const tempBranch = '${{ inputs.temp-branch }}';
37+
const targetBranch = '${{ inputs.target-branch }}';
38+
const dryRun = '${{ inputs.dry-run }}' === 'true';
39+
40+
const prTitle = `Version bump to v${version}`;
41+
const prBody = `## Version Bump to v${version}
42+
43+
This PR updates the version constants for the ${version} release.
44+
45+
### Changes Made:
46+
- Updated \`common.h\` with version \`${version}\`
47+
- Updated \`package.xml\` with version \`${version}\`
48+
- Updated date and time in \`package.xml\`
49+
- Version consistency validated
50+
51+
### Target Branch: \`${targetBranch}\`
52+
53+
### Next Steps:
54+
1. **Review and approve** this version bump
55+
2. **Merge** this PR to \`${targetBranch}\`
56+
3. **Approve tag creation** when prompted
57+
4. **Tag and release** will be created from \`${targetBranch}\`
58+
59+
**Ready for review and merge!** 🚀`;
60+
61+
if (dryRun) {
62+
console.log('DRY RUN: Would create PR with the following details:');
63+
console.log(`Title: ${prTitle}`);
64+
console.log(`Head: ${tempBranch}`);
65+
console.log(`Base: ${targetBranch}`);
66+
console.log('Body:');
67+
console.log(prBody);
68+
69+
// Return a fake PR number for dry run
70+
core.setOutput('pr-number', 999);
71+
return 999;
72+
}
73+
74+
const { data: pr } = await github.rest.pulls.create({
75+
owner: context.repo.owner,
76+
repo: context.repo.repo,
77+
title: prTitle,
78+
head: tempBranch,
79+
base: targetBranch,
80+
body: prBody,
81+
draft: false
82+
});
83+
84+
console.log(`Created PR #${pr.number}: ${pr.html_url}`);
85+
core.setOutput('pr-number', pr.number);
86+
return pr.number;

0 commit comments

Comments
 (0)