-
Notifications
You must be signed in to change notification settings - Fork 1
109 lines (90 loc) · 5.23 KB
/
cvs-patch.yaml
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
name: Generate CVS Patch Per Commit on Main Push
on:
push:
branches:
- main
jobs:
cvs_patch_and_release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # Checkout all commits
- name: Set up Git identity
run: |
git config --local user.name "GitHub Actions"
git config --local user.email "actions@github.com"
- name: Generate patch file
id: generate_patch
run: |
PATCH_DIR="patches"
mkdir -p "$PATCH_DIR"
# Check if it's the initial commit (still handle initial commit gracefully)
if ! git rev-parse --short HEAD~1 > /dev/null 2>&1; then
echo "Initial commit detected. Skipping patch generation for the first commit."
echo "patch_file_name=no-patch-generated" >> "$GITHUB_OUTPUT"
echo "patch_file_path=no-patch-path" >> "$GITHUB_OUTPUT"
echo "patch_generated=false" >> "$GITHUB_OUTPUT"
else
# Generate patch for the range of commits from parent of HEAD to HEAD
COMMIT_RANGE="HEAD^1..HEAD"
echo "Commit range for patch: $COMMIT_RANGE"
git format-patch --no-stat -o "$PATCH_DIR" "$COMMIT_RANGE"
PATCH_FILE=$(find "$PATCH_DIR" -type f -name "*.patch")
if [[ -z "$PATCH_FILE" ]]; then
echo "Info: No patch file generated because no code changes detected in merge (or possibly initial workflow run)."
echo "patch_file_name=no-patch-generated" >> "$GITHUB_OUTPUT"
echo "patch_file_path=no-patch-path" >> "$GITHUB_OUTPUT"
echo "patch_generated=false" >> "$GITHUB_OUTPUT"
exit 1 # Exit with error to prevent further progress and indicate a problem with workflow
else
PATCH_FILE_NAME=$(basename "$PATCH_FILE")
echo "Patch file generated: $PATCH_FILE_NAME"
# Get abbreviated commit hash for HEAD
HEAD_COMMIT_SHORT=$(git rev-parse --short HEAD)
echo "Abbreviated HEAD commit hash: $HEAD_COMMIT_SHORT"
echo "patch_file_name=$PATCH_FILE_NAME" >> "$GITHUB_OUTPUT"
echo "patch_file_path=$PATCH_FILE" >> "$GITHUB_OUTPUT"
echo "patch_generated=true" >> "$GITHUB_OUTPUT"
echo "head_commit_short=$HEAD_COMMIT_SHORT" >> "$GITHUB_OUTPUT"
fi
fi
shell: /usr/bin/bash -e {0} # Use bash instead of sh
- name: Create GitHub Release
if: ${{ steps.generate_patch.outputs.patch_generated == 'true' }} # Conditional release creation
id: create_release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: cvs-sync-release-${{ github.run_id }}
name: CVS Patch Release - Commit ${{ steps.generate_patch.outputs.head_commit_short }}
body: |
## Patch File Generated
A patch file has been automatically generated from the latest changes merged into the `main` branch.
1. **Download the attached patch file from this release.**
**Patch File Name:** ${{ steps.generate_patch.outputs.patch_file_name }}
**Patch File Path:** ${{ steps.generate_patch.outputs.patch_file_path }}
2. **Transfer the patch file** to a machine with access to your CVS pserver and your CVS working copy.
3. **Login to the CVS-capable node.**
4. **Identify the *next* release to apply:** Consult your CVS repository for the latest `git-hash-*` tag. The release to apply is the one for the Git commit *after* the commit hash in the latest CVS tag (or the very first release if no `git-hash-*` tags exist yet). **In most cases, you will simply apply the releases in the order they are created.**
5. **Navigate to the root directory of your CVS working copy** in the terminal.
6. **Apply the patch using the `patch` command:**
```bash
patch -p1 < ${{ steps.generate_patch.outputs.patch_file_path }}
```
7. **Resolve any conflicts** reported by the `patch` command manually in your CVS working copy. Use `cvs update -j <conflicting_revision>` if needed.
8. **Build and thoroughly test** the build process in the CVS environment after applying the patch.
9. **Commit the changes to CVS:**
```bash
cvs commit -m "Sync from Git - Commit ${{ steps.generate_patch.outputs.head_commit_short }}"
```
10. **Crucially, create a CVS tag *immediately* after a *successful* CVS commit:**
```bash
cvs tag git-hash-${{ steps.generate_patch.outputs.head_commit_short }}
```
**Use the Git commit hash `${{ steps.generate_patch.outputs.head_commit_short }}` from this GitHub Release in the CVS tag name.** This tag is essential for tracking the CVS sync state and identifying the next release to apply.
draft: false
prerelease: false
files: ${{ steps.generate_patch.outputs.patch_file_path }}