-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
123 lines (107 loc) · 3.98 KB
/
action.yml
File metadata and controls
123 lines (107 loc) · 3.98 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
name: 'Update self as submodule'
description: 'Update itself as a submodule, and create PR on parent repo'
author: 'RevolveNTNU'
inputs:
self_dot_git:
description: 'Name of .git-file for the current repo'
required: true
name:
description: 'Name to use in text, e.g. PR title ect.'
required: false
default: 'Submodule'
pat_token:
description: 'PAT token valid on parent repo'
required: true
pr_branch_name:
description: 'Name of branch to create on parent. Run ID will be appended'
required: false
default: 'dependencies/submodule-update'
target_branch:
description: 'Target branch on parent'
required: true
checkout_branch:
description: 'Name of branch on self to checkout and pull'
required: false
default: 'master'
parent_repository:
description: 'Parent repository, WITHOUT owner prefix'
required: true
owner:
description: 'Owner of the parent repo'
required: true
label:
description: 'Label to use on PR'
required: false
default: 'dependencies 🛎️'
runs:
using: 'composite'
steps:
- name: "Set environmental variables"
shell: bash
run: |
echo "ID=${GITHUB_RUN_ID}" >> $GITHUB_ENV
echo "BRANCH=${{ inputs.pr_branch_name }}-${GITHUB_RUN_ID}" >> $GITHUB_ENV
- name: Checkout Code
uses: actions/checkout@v3
with:
repository: "${{ inputs.owner }}/${{ inputs.parent_repository }}"
ref: ${{ inputs.target_branch }}
submodules: true
token: ${{ inputs.pat_token }}
- name: Update submodule
shell: bash
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
git config user.name github-actions
git config user.email github-actions@github.com
cd $(git config --file .gitmodules --get-regexp url | grep ${{ inputs.self_dot_git }} | sed -e "s/^submodule.//" -e "s/\.url.*//")
git checkout ${{ inputs.checkout_branch }}
git pull
cd -
- name: Commit and push
shell: bash
run: |
git checkout -b ${{ env.BRANCH }}
git add .
git commit -m "Update ${{ inputs.name }}"
git push --set-upstream origin ${{ env.BRANCH }}
- name: Create pull request against target branch
id: create_pr
uses: actions/github-script@v5
with:
github-token: ${{ inputs.pat_token }}
script: |
try {
const pr = await github.rest.pulls.create({
owner: '${{ inputs.owner }}',
repo: '${{ inputs.parent_repository }}',
head: '${{ env.BRANCH }}',
base: '${{ inputs.target_branch }}',
title: `[Auto-generated] ${{ inputs.name }} updates ${{ env.ID }}`,
body: `Update the ${{ inputs.name }}-submodule to latest master`,
});
return pr.data.number;
} catch (error) {
console.error('Error creating pull request:', error);
throw new Error('Failed to create pull request');
}
- name: Add labels
uses: actions/github-script@v5
with:
github-token: ${{ inputs.pat_token }}
script: |
const prNumber = ${{ steps.create_pr.outputs.result }};
if (prNumber) {
try {
await github.rest.issues.addLabels({
issue_number: prNumber,
owner: '${{ inputs.owner }}',
repo: '${{ inputs.parent_repository }}',
labels: ['${{ inputs.label }}']
});
} catch (error) {
console.error('Error adding label to PR', error);
}
} else {
console.error('No PR number returned, skipping label addition');
}