Skip to content

Commit a0248fb

Browse files
authored
Merge pull request #1307 from Azure/jcotillo/automerge_action
Enable automerge - github action
2 parents c561a5e + 69507cc commit a0248fb

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

.github/workflows/main.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,41 @@ jobs:
2323
- name: Run CI tests
2424
run: npm test
2525
working-directory: ./tools
26+
27+
automerge:
28+
runs-on: ubuntu-latest
29+
needs: build
30+
if: ${{ github.actor == 'AzureSDKAutomation' && startsWith(github.head_ref, 'sdkAutomation') }}
31+
steps:
32+
- uses: actions/checkout@v2
33+
34+
- name: Setup Node.js
35+
uses: actions/setup-node@v2.1.2
36+
with:
37+
node-version: 10.x
38+
39+
- name: Install NPM modules
40+
run: npm ci
41+
working-directory: ./generator
42+
43+
- name: Check RP in Autogenlist
44+
run: |
45+
check_result='';
46+
exec=$(npm run find-basepath ${{ github.head_ref }});
47+
while read line;
48+
do
49+
# overriding check_result until the last line is read, last line contains
50+
# the result to whether or not the basepath was found in autogenlist.
51+
check_result=$line;
52+
echo $check_result;
53+
done <<< "$exec";
54+
55+
echo "AUTOGENLIST_CHECK_RESULT=$check_result" >> $GITHUB_ENV;
56+
working-directory: ./generator
57+
58+
- name: Automerge
59+
if: ${{ env.AUTOGENLIST_CHECK_RESULT == 'true' }}
60+
uses: "pascalgn/automerge-action@v0.12.0"
61+
env:
62+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
63+
MERGE_LABELS: ""

generator/cmd/findbasepath.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { executeSynchronous } from '../utils';
2+
import { findAutogenEntries } from '../autogenlist';
3+
4+
// this function analyzes a branch name and extracts the base path, then proceeds to find it in autogenlist
5+
// if not found, it throws an error
6+
executeSynchronous(async () => {
7+
if (!process.argv[2]) {
8+
throw new Error("Branch name missing. This cmd expects a branch name with the following format: 'sdkAutomation/[basepath]'");
9+
}
10+
11+
const prName = process.argv[2];
12+
let basePath = prName.replace("sdkAutomation/", "");
13+
14+
// format basePath
15+
basePath = `${basePath}/resource-manager`;
16+
17+
const autogenEntries = findAutogenEntries(basePath);
18+
19+
if (autogenEntries.length === 0) {
20+
//not found
21+
console.log("false");
22+
return;
23+
}
24+
25+
console.log(`Base path: '${basePath} found in autogenlist.`);
26+
console.log("true");
27+
});

generator/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"list-basepaths": "ts-node cmd/listbasepaths",
77
"list-resources": "ts-node cmd/listresources",
88
"generate-all": "ts-node cmd/generateall",
9+
"find-basepath": "ts-node cmd/findbasepath",
910
"generate-single": "ts-node cmd/generatesingle",
1011
"clean": "ts-node cmd/clean",
1112
"start": "npm run clean && npm run generate-all",

0 commit comments

Comments
 (0)