Schedule build examples #3063
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Schedule build examples | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '* * * * *' # Schedule every 5 minutes | |
jobs: | |
schedule_build_examples: | |
name: Schedule build examples | |
runs-on: ubuntu-latest | |
timeout-minutes: 60 | |
strategy: | |
matrix: | |
build: | |
- repo: 'Agora-Flutter-SDK' | |
apple-package-name: 'io.agora.agoraRtcEngineExample' | |
flutter-package-name: 'agora_rtc_engine' | |
- repo: 'Agora-Flutter-RTM-SDK' | |
apple-package-name: 'io.agora.agoraRtmExample' | |
flutter-package-name: 'agora_rtm' | |
steps: | |
- name: Schedule build examples | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.ACTION_PAT }} | |
retries: 3 | |
debug: true | |
script: | | |
const buildExampleRepo = `${{ matrix.build.repo }}`; | |
// https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#list-pull-requests | |
const response = await github.request('GET /repos/{owner}/{repo}/pulls', { | |
owner: 'AgoraIO-Extensions', | |
repo: buildExampleRepo, | |
headers: { | |
'X-GitHub-Api-Version': '2022-11-28' | |
} | |
}); | |
if (response.status != 200) { | |
console.log(`Failed: ${response.data}`); | |
return; | |
} | |
console.log(`response.data: ${response.data}`); | |
const prs = response.data; | |
for (let pr of prs) { | |
let prNumber = pr.number; | |
let targetBranch = pr.head.ref; | |
console.log(`pr.labels: ${pr.labels}`); | |
let isScheduleBuildExample = false; | |
let isBuildingExample = false; | |
for (let label of pr.labels) { | |
console.log(`label.name: ${label.name}`); | |
if (label.name == "ci:schedule_build_example") { | |
isScheduleBuildExample = true; | |
} | |
if (label.name == "ci:building_example") { | |
isBuildingExample = true; | |
} | |
} | |
if (isBuildingExample) { | |
console.log(`Skip schedule due to the build is processing...`); | |
continue; | |
} | |
if (!isScheduleBuildExample) { | |
continue; | |
} | |
await github.rest.issues.addLabels({ | |
issue_number: prNumber, | |
owner: 'AgoraIO-Extensions', | |
repo: buildExampleRepo, | |
labels: ['ci:building_example'] | |
}) | |
const owner = "AgoraIO-Extensions" | |
const repo = "agora_flutter_sdks_build" | |
const workflow_id = "build_and_post_result_to_pr.yml" | |
const ref = 'main' | |
const applePackageName = `${{ matrix.build.apple-package-name }}`; | |
const flutterPackageName = `${{ matrix.build.flutter-package-name }}`; | |
// see https://docs.github.com/en/rest/actions/workflows?apiVersion=2022-11-28#create-a-workflow-dispatch-event | |
github.request(`POST /repos/${owner}/${repo}/actions/workflows/${workflow_id}/dispatches`, { | |
ref: ref, | |
inputs: { | |
'target_repo': `AgoraIO-Extensions/${buildExampleRepo}`, | |
'target_branch': targetBranch, | |
'pr_number': `${prNumber}`, | |
'apple-package-name': applePackageName, | |
'flutter-package-name': flutterPackageName, | |
}, | |
headers: { | |
'X-GitHub-Api-Version': '2022-11-28' | |
} | |
}); | |
console.log(`Scheduled build...`); | |
} |