Skip to content

Commit

Permalink
[CI] Trigger workflow (#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
hjjq committed Jan 17, 2024
1 parent 53922fc commit f58cc3f
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 33 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/launch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Launch CI


on:
workflow_dispatch:
inputs:
shutdown_instances:
description: 'Shut down GPU instances when finished.'
required: true
type: boolean
default: true
issue_comment:
types: [created]


jobs:
trigger:
if: |
github.event_name == 'workflow_dispatch' ||
github.event_name == 'issue_comment' && github.event.issue.pull_request != '' &&
contains(fromJSON('["MEMBER", "OWNER", "COLLABORATOR"]'), github.event.comment.author_association) &&
contains(github.event.comment.body, '$hidet-ci launch')
runs-on: ubuntu-latest
steps:
- name: Trigger workflow in internal repository
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GH_PAT }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ secrets.REPO_NAME }}/actions/workflows/regression.yaml/dispatches \
-d "{\"ref\": \"main\", \"inputs\": {\"shutdown_instances\": \"${{ env.SHUTDOWN }}\", \"source_repo\": \"${{ env.SOURCE_REPO }}\", \"source_ref\": \"${{ env.SOURCE_REF }}\"}}"
env:
SHUTDOWN: ${{ github.event_name == 'workflow_dispatch' && inputs.shutdown_instances || !contains(github.event.comment.body, '--keep') }}
SOURCE_REPO: ${{ github.repository }}
SOURCE_REF: ${{ github.event_name == 'workflow_dispatch' && github.ref_name || github.event.issue.number }}
71 changes: 38 additions & 33 deletions .github/workflows/regression.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ on:
required: true
type: boolean
default: true
issue_comment:
types: [created]
source_repo:
description: 'Source Repository Name. E.g, hidet-org/hidet'
required: true
type: string
default: 'this'
source_ref:
description: 'Source repository ref (Branch name or PR number).'
required: true
type: string
default: 'this'

jobs:
start_instances:
if: |
github.event_name == 'workflow_dispatch' ||
github.event_name == 'issue_comment' && github.event.issue.pull_request != '' &&
contains(fromJSON('["MEMBER", "OWNER", "COLLABORATOR"]'), github.event.comment.author_association) &&
contains(github.event.comment.body, '$hidet-ci launch')
runs-on: ubuntu-latest
outputs:
started_instances: ${{ steps.run_py_script.outputs.started_instances }}
Expand Down Expand Up @@ -61,13 +64,20 @@ jobs:
container:
image: nvcr.io/nvidia/pytorch:23.10-py3
options: --gpus all
outputs:
commit_time: ${{ steps.get_commit_info.outputs.commit_time }}
commit_author: ${{ steps.get_commit_info.outputs.commit_author }}
commit_sha: ${{ steps.get_commit_info.outputs.commit_sha }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
repository: |
${{ inputs.source_repo == 'this' && github.repository ||
inputs.source_repo }}
ref: |
${{ github.event_name == 'workflow_dispatch' && github.ref_name ||
format('refs/pull/{0}/head', github.event.issue.number) }}
${{ inputs.source_repo == 'this' && github.ref_name ||
format('refs/pull/{0}/head', inputs.source_ref) }}
path: hidet

- name: Checkout models
Expand Down Expand Up @@ -114,10 +124,8 @@ jobs:
python hidet/.github/scripts/run_tests.py
env:
HW_CONFIG: ${{ matrix.hw_configs }}
REPO_NAME: ${{ github.repository }}
REPO_BRANCH: |
${{ github.event_name == 'workflow_dispatch' && github.ref_name ||
format('pull/{0}', github.event.issue.number) }}
REPO_NAME: ${{ inputs.source_repo == 'this' && github.repository || inputs.source_repo }}
REPO_BRANCH: ${{ inputs.source_repo == 'this' && github.ref_name || format('pull/{0}', inputs.source_ref) }}
CI_CS_HOSTNAME: ${{ secrets.CI_CS_HOSTNAME }}
CI_CS_PORT: ${{ secrets.CI_CS_PORT }}
CI_CS_USERNAME: ${{ secrets.CI_CS_USERNAME }}
Expand All @@ -130,6 +138,17 @@ jobs:
name: run_configs_${{ matrix.hw_configs }}
path: run_configs.json
retention-days: 1

- name: Retrieve commit properties
id: get_commit_info
run: |
cd hidet
COMMIT_TIME=$(git log -1 --format=%cd --date=format:'%Y-%m-%d %H:%M:%S')
COMMIT_AUTHOR=$(git log -1 --format=%an)
COMMIT_SHA=$(git log -1 --format=%H)
echo "commit_time=$COMMIT_TIME" >> $GITHUB_OUTPUT
echo "commit_author=$COMMIT_AUTHOR" >> $GITHUB_OUTPUT
echo "commit_sha=$COMMIT_SHA" >> $GITHUB_OUTPUT
upload_results:
runs-on: ubuntu-latest
Expand All @@ -143,37 +162,23 @@ jobs:

- name: Download run configs
uses: actions/download-artifact@v3

- name: Setup ENV
run: |
COMMIT_TIME=$(git log -1 --format=%cd --date=format:'%Y-%m-%d %H:%M:%S')
COMMIT_AUTHOR=$(git log -1 --format=%an)
COMMIT_SHA=$(git log -1 --format=%H)
echo "COMMIT_TIME=$COMMIT_TIME" >> $GITHUB_ENV
echo "COMMIT_AUTHOR=$COMMIT_AUTHOR" >> $GITHUB_ENV
echo "COMMIT_SHA=$COMMIT_SHA" >> $GITHUB_ENV

- name: Run main Python script
run: python ./.github/scripts/upload_results.py
env:
REPO_NAME: ${{ github.repository }}
REPO_BRANCH: |
${{ github.event_name == 'workflow_dispatch' && github.ref_name ||
format('pull/{0}', github.event.issue.number) }}
COMMIT_SHA: ${{ env.COMMIT_SHA }}
COMMIT_TIME: ${{ env.COMMIT_TIME }}
COMMIT_AUTHOR: ${{ env.COMMIT_AUTHOR }}
REPO_NAME: ${{ inputs.source_repo == 'this' && github.repository || inputs.source_repo }}
REPO_BRANCH: ${{ inputs.source_repo == 'this' && github.ref_name || format('pull/{0}', inputs.source_ref) }}
COMMIT_SHA: ${{ needs.run_tests.outputs.commit_sha }}
COMMIT_TIME: ${{ needs.run_tests.outputs.commit_time }}
COMMIT_AUTHOR: ${{ needs.run_tests.outputs.commit_author }}
HW_CONFIGS: ${{ needs.start_instances.outputs.hw_configs }}
CI_DB_HOSTNAME: ${{ secrets.CI_DB_HOSTNAME }}
CI_DB_PORT: ${{ secrets.CI_DB_PORT }}
CI_DB_USERNAME: ${{ secrets.CI_DB_USERNAME }}
CI_DB_PASSWORD: ${{ secrets.CI_DB_PASSWORD }}

stop_instances:
if: |
github.event_name == 'workflow_dispatch' && inputs.shutdown_instances ||
github.event_name == 'issue_comment' && github.event.issue.pull_request != '' &&
!contains(github.event.comment.body, '--keep')
if: inputs.shutdown_instances
runs-on: ubuntu-latest
needs: [start_instances, run_tests]
steps:
Expand Down

0 comments on commit f58cc3f

Please sign in to comment.