forked from vercel/pkg-fetch
-
-
Notifications
You must be signed in to change notification settings - Fork 13
88 lines (73 loc) · 3.47 KB
/
patch-node.yml
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
name: Create new Node.js patch
on:
workflow_dispatch:
inputs:
nodeVersion:
description: 'Node.js version (e.g. 20.11.0)'
default: ''
type: string
required: true
patchFile:
description: 'Patch version to use (e.g. 20.11.0). Leave empty to use the matching major patch'
default: ''
type: string
required: false
jobs:
build:
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Checkout nodejs and create new patch
run: |
# find the patch file by checking the patch file matching major version input node version
MAJOR_VERSION=$(echo ${{ inputs.nodeVersion }} | cut -d'.' -f1)
echo "Node.js major version: $MAJOR_VERSION"
if [ -z "${{ inputs.patchFile }}" ]; then
PATCH_FILE=$(ls patches/node.v$MAJOR_VERSION.*.patch)
else
PATCH_FILE=patches/node.v${{ inputs.patchFile }}.cpp.patch
fi
# extract patch version from PATCH_FILE. E.g. node.v20.11.1.cpp.patch --> 20.11.1
PATCH_VERSION=$(echo $PATCH_FILE | grep -oP 'node.v\K[0-9]+\.[0-9]+\.[0-9]+')
echo "Patch file: $PATCH_FILE"
# check if patch file exists
if [ ! -f "$PATCH_FILE" ]; then
echo "No patch file found for Node.js version ${{ inputs.nodeVersion }}"
exit 1
fi
cd ..
echo "Cloning Node.js repository"
git clone -b v${{ inputs.nodeVersion }} --single-branch https://github.com/nodejs/node.git
cd node
# apply the patch, if there are conflicts exit with error
echo "Applying patch $PATCH_FILE"
git apply --check ../pkg-fetch/$PATCH_FILE
if [ $? -ne 0 ]; then
echo "Patch $PATCH_FILE does not apply cleanly"
exit 1
fi
echo "Patch $PATCH_FILE applies cleanly, creating new patch file"
git apply ../pkg-fetch/$PATCH_FILE
# delete old patch file and create new one
rm -rf ../pkg-fetch/$PATCH_FILE
git add -A
git diff --staged --src-prefix=node/ --dst-prefix=node/ > ../pkg-fetch/patches/node.v${{ inputs.nodeVersion }}.cpp.patch
# Update patches.json
echo "Updating patches.json"
cd ../pkg-fetch/patches
sed -i "s/\"v$PATCH_VERSION\": \[\"node.v$PATCH_VERSION.cpp.patch\"\]/\"v${{ inputs.nodeVersion }}\": \[\"node.v${{ inputs.nodeVersion }}.cpp.patch\"\]/" patches.json
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "feat: add v${{ inputs.nodeVersion }} patch"
title: "feat: add v${{ inputs.nodeVersion }} patch"
body: "This PR bumps the Node.js patch version to v${{ inputs.nodeVersion }}"
branch: "nodejs-v${{ inputs.nodeVersion }}"
base: "main"
delete-branch: true
labels: "enhancement, nodejs"
draft: false