Skip to content

Commit

Permalink
Merge pull request #1307 from Azure/jcotillo/automerge_action
Browse files Browse the repository at this point in the history
Enable automerge - github action
  • Loading branch information
jorgecotillo authored Nov 10, 2020
2 parents c561a5e + 69507cc commit a0248fb
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,41 @@ jobs:
- name: Run CI tests
run: npm test
working-directory: ./tools

automerge:
runs-on: ubuntu-latest
needs: build
if: ${{ github.actor == 'AzureSDKAutomation' && startsWith(github.head_ref, 'sdkAutomation') }}
steps:
- uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/[email protected]
with:
node-version: 10.x

- name: Install NPM modules
run: npm ci
working-directory: ./generator

- name: Check RP in Autogenlist
run: |
check_result='';
exec=$(npm run find-basepath ${{ github.head_ref }});
while read line;
do
# overriding check_result until the last line is read, last line contains
# the result to whether or not the basepath was found in autogenlist.
check_result=$line;
echo $check_result;
done <<< "$exec";
echo "AUTOGENLIST_CHECK_RESULT=$check_result" >> $GITHUB_ENV;
working-directory: ./generator

- name: Automerge
if: ${{ env.AUTOGENLIST_CHECK_RESULT == 'true' }}
uses: "pascalgn/[email protected]"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
MERGE_LABELS: ""
27 changes: 27 additions & 0 deletions generator/cmd/findbasepath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { executeSynchronous } from '../utils';
import { findAutogenEntries } from '../autogenlist';

// this function analyzes a branch name and extracts the base path, then proceeds to find it in autogenlist
// if not found, it throws an error
executeSynchronous(async () => {
if (!process.argv[2]) {
throw new Error("Branch name missing. This cmd expects a branch name with the following format: 'sdkAutomation/[basepath]'");
}

const prName = process.argv[2];
let basePath = prName.replace("sdkAutomation/", "");

// format basePath
basePath = `${basePath}/resource-manager`;

const autogenEntries = findAutogenEntries(basePath);

if (autogenEntries.length === 0) {
//not found
console.log("false");
return;
}

console.log(`Base path: '${basePath} found in autogenlist.`);
console.log("true");
});
1 change: 1 addition & 0 deletions generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"list-basepaths": "ts-node cmd/listbasepaths",
"list-resources": "ts-node cmd/listresources",
"generate-all": "ts-node cmd/generateall",
"find-basepath": "ts-node cmd/findbasepath",
"generate-single": "ts-node cmd/generatesingle",
"clean": "ts-node cmd/clean",
"start": "npm run clean && npm run generate-all",
Expand Down

0 comments on commit a0248fb

Please sign in to comment.