-
-
Notifications
You must be signed in to change notification settings - Fork 13
141 lines (119 loc) · 4.74 KB
/
ci-patch.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
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
name: CI Patch
on:
push:
branches:
- 'patch*'
pull_request:
branches:
- 'dev'
types: [synchronize]
jobs:
handle:
runs-on: ubuntu-latest
if: github.repository == 'kbve/kbve'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fetch dev branch
run: git fetch origin dev
- name: Get Commits
id: get_commits
run: |
commits=$(git log --oneline origin/dev..HEAD | tr '\n' '|')
echo "commits=$commits" >> $GITHUB_OUTPUT
create_pr:
if: github.event_name == 'push' && github.repository == 'kbve/kbve'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
# - name: Auto-Pull
# uses: diillson/auto-pull-request@latest
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# destination_branch: 'dev'
# pr_title: 'Pulling ${{ github.ref }} into Dev'
# pr_body: |
# *An automated PR*
# Commits:
# ${{ steps.get_commits.outputs.commits }}
# pr_label: 'auto-pr'
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Create temp directory and install @kbve/devops
run: |
mkdir -p /tmp/devops-temp
cd /tmp/devops-temp
npm install @kbve/devops --legacy-peer-deps
- name: Call Process and Update PR Function
uses: actions/github-script@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_PATH: /tmp/devops-temp/node_modules
with:
script: |
const { _$gha_processAndUpdatePR, _$gha_createOrUpdatePR } = require('@kbve/devops');
// Safely get the reference branch from github.ref or pull request context
let referenceBranch = null;
// Log the event name to understand the context
console.log(`GitHub Event Name: ${github.event_name}`);
if (github.ref) {
// If github.ref is available, extract branch name
referenceBranch = github.ref.replace('refs/heads/', '');
console.log(`Using github.ref: ${referenceBranch}`);
} else if (context.payload && context.payload.pull_request && context.payload.pull_request.head) {
// If this is a pull request, get the head branch
referenceBranch = context.payload.pull_request.head.ref;
console.log(`Using context.payload.pull_request.head.ref: ${referenceBranch}`);
} else if (context.ref) {
// Fallback: If neither of the above work, try context.ref
referenceBranch = context.ref.replace('refs/heads/', '');
console.log(`Using context.ref: ${referenceBranch}`);
} else {
// If no branch can be determined, log an error and fail
console.error("Unable to determine the reference branch.");
throw new Error("Unable to determine the reference branch.");
}
if (!referenceBranch) {
console.error("Reference branch is still null after checks.");
throw new Error("Unable to determine the reference branch.");
}
const targetBranch = 'dev';
// Call function to create or update the pull request
await _$gha_createOrUpdatePR(github, context, referenceBranch, targetBranch);
// Now process and update the pull request
const branchToCompare = 'dev';
await _$gha_processAndUpdatePR(branchToCompare, github, context);
update_pr:
if: github.event.action == 'synchronize' && github.repository == 'kbve/kbve'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Create temp directory and install @kbve/devops
run: |
mkdir -p /tmp/devops-temp
cd /tmp/devops-temp
npm install @kbve/devops --legacy-peer-deps
- name: Call Process and Update PR Function
uses: actions/github-script@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_PATH: /tmp/devops-temp/node_modules
with:
script: |
const { _$gha_processAndUpdatePR } = require('@kbve/devops');
const branchToCompare = 'dev';
await _$gha_processAndUpdatePR(branchToCompare, github, context);