Improve static typing and mypy compatibility #52
Workflow file for this run
This file contains hidden or 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: Test and Deploy | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
workflow_dispatch: | |
env: | |
OMEGAUPUSER: ${{ secrets.OMEGAUPUSER }} | |
OMEGAUP_API_TOKEN: ${{ secrets.OMEGAUP_API_TOKEN }} | |
GIT_USERNAME: ${{ github.actor }} | |
GIT_PASSWORD: ${{ secrets.GITHUB_TOKEN }} | |
FIX_COMMIT_MESSAGE: Fixed /hook_tools/lint.py lints | |
jobs: | |
build-test-deploy: | |
if: github.event_name != 'pull_request' || github.event.pull_request.head.ref != 'sync-course' | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Cancel if merged from sync-course | |
if: github.ref == 'refs/heads/main' | |
run: | | |
if git log -1 --merges --pretty=%B | grep -q 'sync-course'; then | |
echo "Merged from sync-course. Skipping workflow." | |
exit 0 | |
fi | |
- name: Set base commit (pull request) | |
run: | | |
echo "GITHUB_BASE_COMMIT=${{ github.event.pull_request.base.sha }}" >> $GITHUB_ENV | |
echo "GITHUB_CURRENT_COMMIT=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV | |
if: github.ref != 'refs/heads/main' | |
- name: Set base commit (main) | |
run: | | |
echo "GITHUB_BASE_COMMIT=${{ github.event.before }}" >> $GITHUB_ENV | |
echo "GITHUB_CURRENT_COMMIT=${{ github.event.after }}" >> $GITHUB_ENV | |
if: github.ref == 'refs/heads/main' | |
- name: Set up environment | |
run: | | |
git config --global core.quotePath false | |
echo "PIPENV_PIPFILE=$(pwd)/utils/Pipfile" >> $GITHUB_ENV | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.11' | |
- uses: actions/checkout@v2 | |
with: | |
ref: ${{ env.GITHUB_CURRENT_COMMIT }} | |
fetch-depth: 0 | |
submodules: true | |
- name: Install Python dependencies | |
run: | | |
python -m pip install --upgrade pip | |
(cd utils && sudo pip install pipenv==2023.11.15 && pipenv install) | |
- name: Set up the CI flags | |
run: | | |
if git diff-tree --quiet ${{ env.GITHUB_BASE_COMMIT }} ${{ env.GITHUB_CURRENT_COMMIT }} -- utils/; then | |
echo "CI_FLAGS=--ci" >> $GITHUB_ENV | |
else | |
echo "CI_FLAGS=--ci --all" >> $GITHUB_ENV | |
fi | |
- name: Download omegaUp-ci container | |
run: | | |
docker login https://docker.pkg.github.com -u ${{ github.actor }} -p ${{ github.token }} | |
python3 ./utils/runtests.py ${{ env.CI_FLAGS }} --only-pull-image | |
# - name: Run tests | |
# run: python3 ./utils/runtests.py ${{ env.CI_FLAGS }} | |
- name: Generate pngs/testplan | |
run: python3 ./utils/generateresources.py --generate=png,testplan ${{ env.CI_FLAGS }} | |
if: github.ref == 'refs/heads/main' | |
- name: Deploy to omegaUp | |
run: pipenv run python3 ./utils/upload.py --ci --verbose | |
if: github.ref == 'refs/heads/main' | |
- name: Push to public branch | |
if: github.ref == 'refs/heads/main' | |
run: | | |
shopt -s extglob | |
git config --global user.name "${{ env.GIT_USERNAME }}" | |
git config --global user.email "${{ env.GIT_USERNAME }}@users.noreply.github.com" | |
git add -f !(results) | |
git commit --allow-empty -m "Generated files from $GITHUB_SHA" | |
TMP_COMMIT=$(git rev-parse HEAD) | |
git checkout public | |
git merge --no-commit --no-ff -X theirs $TMP_COMMIT | |
git commit --allow-empty -m "Auto deployed from $GITHUB_SHA" | |
git push origin public | |
- name: Zip logs | |
if: ${{ always() }} | |
run: | | |
if [[ -d results/ && "$(find results/ -type f)" != "" ]]; then | |
(cd results && zip -r ../results.zip .) | |
fi | |
- name: Upload logs | |
if: ${{ always() }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: omegaUp-CI-logs | |
path: results.zip | |
# - name: Notify Slack on failure | |
# uses: 8398a7/action-slack@v3 | |
# with: | |
# status: ${{ job.status }} | |
# fields: repo,message,commit,author,action,eventName,ref,workflow | |
# env: | |
# GITHUB_TOKEN: ${{ github.token }} | |
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | |
# if: ${{ failure() && github.ref == 'refs/heads/main' }} | |
validate-content: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.head_ref }} | |
fetch-depth: 0 | |
submodules: true | |
- name: Set base commit (pull request) | |
run: | | |
echo "GITHUB_BASE_COMMIT=${{ github.event.pull_request.base.sha }}" >> $GITHUB_ENV | |
echo "GITHUB_CURRENT_COMMIT=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV | |
if: github.ref != 'refs/heads/main' | |
- name: Set base commit (main) | |
run: | | |
echo "GITHUB_BASE_COMMIT=${{ github.event.before }}" >> $GITHUB_ENV | |
echo "GITHUB_CURRENT_COMMIT=${{ github.event.after }}" >> $GITHUB_ENV | |
if: github.ref == 'refs/heads/main' | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.11' | |
- name: Validate content structure | |
run: | | |
cd utils | |
python validate_content.py | |
lint: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.head_ref }} | |
fetch-depth: 0 | |
submodules: true | |
- name: Pull container | |
run: ./utils/lint --only-pull-image | |
- name: Validate lint | |
run: | | |
echo "Running lint validation..." | |
if ! ./utils/lint \ | |
--command-name="utils/lint" \ | |
--diagnostics-output=github \ | |
validate --all; then | |
echo "❌ Lint errors detected." | |
echo "Please run the following locally to fix them:" | |
echo "" | |
echo " ./utils/lint fix --all" | |
echo " git commit -am 'Fix lints'" | |
echo " git push" | |
echo "" | |
exit 1 | |
fi |