Discover CI On PR Comment #33
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
# Discover on demand | |
name: Discover CI On PR Comment | |
on: | |
issue_comment: | |
types: [created] | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
bot: | |
runs-on: ubuntu-latest | |
if: ${{ github.event.issue.pull_request }} | |
outputs: | |
experiment-name: ${{ steps.experience.outputs.name }} | |
experiment-action: ${{ steps.experience.outputs.action }} | |
branch: ${{ steps.get-branch.outputs.branch }} | |
steps: | |
- name: Bot help | |
id: check | |
if: contains(github.event.comment.body, '/bot help') | |
shell: bash | |
run: | | |
gh pr comment $PR_NO --body "Bot commands:\n /bot experience --name=[per experiment.yaml] --action=[All, Validation, Benchmark]" | |
gh run cancel ${{ github.run_id }} | |
gh run watch ${{ github.run_id }} | |
env: | |
PR_NO: ${{ github.event.issue.number }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Bot experience | |
id: experience | |
if: contains(github.event.comment.body, '/bot experience') | |
shell: bash | |
run: | | |
echo Launching Discover CI: ${{github.event.comment.body}} | |
BODY="${{github.event.comment.body}}" | |
EXP_NAME_DIRTY=${BODY#*--name=} | |
EXP_NAME=${EXP_NAME_DIRTY%% *} | |
echo "name=${EXP_NAME}" >> "$GITHUB_OUTPUT" | |
EXP_ACTION_DIRTY=${BODY#*--action=} | |
EXP_ACTION=${EXP_ACTION_DIRTY%% *} | |
echo "action=${EXP_ACTION}" >> "$GITHUB_OUTPUT" | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: 'Discover experiment started 🚀\n Parameters: ${EXP_NAME} ${EXP_ACTION}\m Url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}', | |
}); | |
- name: Extract branch | |
id: 'get-branch' | |
run: echo ::set-output name=branch::$(gh pr view $PR_NO --repo $REPO --json headRefName --jq '.headRefName') | |
env: | |
REPO: ${{ github.repository }} | |
PR_NO: ${{ github.event.issue.number }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
respond-to-query-as-comment: | |
needs: [bot] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Acknowledge | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
run-discover-ondemand: | |
needs: bot | |
uses: GEOS-ESM/CI-workflows/.github/workflows/geosongpu-ondemand.yml@project/geosongpu | |
with: | |
experiment_name: ${{ needs.bot.outputs.experiment-name }} | |
experiment_action: ${{ needs.bot.outputs.experiment-action }} | |
geosongpu_ci_ref: ${{ needs.bot.outputs.branch }} | |
comment-results: | |
if: success() || failure() | |
needs: [run-discover-ondemand, bot] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Message success | |
if: ${{ needs.run-discover-ondemand.result == 'success' }} | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: '✅ Successful discover experiment ${{ needs.bot.outputs.experiment-name }} @ ${{ needs.bot.outputs.experiment-action }}', | |
}); | |
- name: Message failure | |
if: ${{ needs.run-discover-ondemand.result != 'success' }} | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: '❌ Failed discover experiment ${{ needs.bot.outputs.experiment-name }} @ ${{ needs.bot.outputs.experiment-action }}', | |
}); |