Documentation first pass #38
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: Cancel job if needed | |
id: conditional-cancel | |
if: "!contains(github.event.comment.body, '/bot')" | |
shell: bash | |
run: | | |
gh run --repo $REPO cancel ${{ github.run_id }} | |
gh run --repo $REPO watch ${{ github.run_id }} | |
env: | |
REPO: ${{ github.repository }} | |
PR_NO: ${{ github.event.issue.number }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Bot help | |
id: check | |
if: contains(github.event.comment.body, '/bot help') | |
shell: bash | |
run: | | |
gh pr comment $PR_NO --repo $REPO --body 'Bot commands: | |
/bot help | |
: Print this message | |
/bot experience --name=[per experiment.yaml] --action=[All, Validation, Benchmark] | |
: Triggers a geosongpu_dispatch command with given parameters' | |
gh run --repo $REPO cancel ${{ github.run_id }} | |
gh run --repo $REPO watch ${{ github.run_id }} | |
env: | |
REPO: ${{ github.repository }} | |
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" | |
gh pr comment $PR_NO --repo $REPO --body 'Discover experiment started 🚀: | |
Parameters: ${EXP_NAME} ${EXP_ACTION} | |
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: | | |
gh pr comment $PR_NO --repo $REPO --body '✅ Successful discover experiment ${{ needs.bot.outputs.experiment-name }} @ ${{ needs.bot.outputs.experiment-action }}' | |
env: | |
REPO: ${{ github.repository }} | |
PR_NO: ${{ github.event.issue.number }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Message failure | |
if: ${{ needs.run-discover-ondemand.result != 'success' }} | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
gh pr comment $PR_NO --repo $REPO --body '❌ Failed discover experiment ${{ needs.bot.outputs.experiment-name }} @ ${{ needs.bot.outputs.experiment-action }}' | |
env: | |
REPO: ${{ github.repository }} | |
PR_NO: ${{ github.event.issue.number }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |