-
Notifications
You must be signed in to change notification settings - Fork 71
Migrate CI/CD from Travis to GitHub Actions #391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+348
−54
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # CI/CD and Release | ||
|
|
||
| This repository uses [GitHub Actions](https://github.com/Cloud-CV/evalai-cli/actions) for continuous integration and package publishing. | ||
|
|
||
| ## Workflows | ||
|
|
||
| | Workflow | Purpose | | ||
| |----------|---------| | ||
| | `ci-cd.yml` | Lint, test, and publish packages | | ||
| | `upload-coverage.yml` | Upload test coverage to Codecov after CI succeeds | | ||
|
|
||
| ## Required repository secrets | ||
|
|
||
| Configure these under **Settings → Secrets and variables → Actions**: | ||
|
|
||
| | Secret | Used for | | ||
| |--------|----------| | ||
| | `CODECOV_TOKEN` | Codecov upload | | ||
| | `TEST_PYPI_USERNAME` | TestPyPI publish on `staging` pushes | | ||
| | `TEST_PYPI_PASSWORD` | TestPyPI publish on `staging` pushes | | ||
| | `PYPI_API_TOKEN` | Production PyPI publish on tag pushes | | ||
|
|
||
| ## GitHub environments | ||
|
|
||
| Create optional environments for publish job scoping and approvals: | ||
|
|
||
| - `staging` — TestPyPI publishes from the `staging` branch | ||
| - `production` — PyPI publishes from git tags | ||
|
|
||
| ## Release process | ||
|
|
||
| 1. Bump the version in `evalai/version.py`. | ||
| 2. Push to `staging` to publish a test build to [TestPyPI](https://test.pypi.org/project/evalai/). | ||
| 3. Create and push a git tag to publish to [PyPI](https://pypi.org/project/evalai/). | ||
|
|
||
| CI runs on pull requests and pushes to `master` and `staging` using Python 3.9.21 (aligned with the main EvalAI repository). |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| name: ci-cd | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
| - staging | ||
| tags: | ||
| - "*" | ||
| pull_request: | ||
| workflow_dispatch: | ||
| inputs: | ||
| publish_target: | ||
| description: "Optional manual publish target" | ||
| required: true | ||
| type: choice | ||
| options: | ||
| - none | ||
| - testpypi | ||
| default: none | ||
|
|
||
| concurrency: | ||
| group: ci-cd-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| env: | ||
| PYTHON_RUNTIME_VERSION: "3.9.21" | ||
|
|
||
| jobs: | ||
| code_quality: | ||
| name: Code quality | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 | ||
| with: | ||
| python-version: ${{ env.PYTHON_RUNTIME_VERSION }} | ||
| cache: pip | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install -r requirements.txt | ||
| pip install flake8==7.1.2 | ||
|
|
||
| - name: Run flake8 | ||
| run: flake8 ./ | ||
|
|
||
| test: | ||
| name: Tests | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| actions: write | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 | ||
| with: | ||
| python-version: ${{ env.PYTHON_RUNTIME_VERSION }} | ||
| cache: pip | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip setuptools==70.0.0 | ||
| pip install -r requirements.txt | ||
| pip install \ | ||
| coverage \ | ||
| pytest==3.5.1 \ | ||
| pytest-cov==2.5.1 \ | ||
| pytest-env==0.6.2 \ | ||
| responses==0.9.0 | ||
|
|
||
| - name: Run tests with coverage | ||
| run: | | ||
| pytest \ | ||
| --cov evalai \ | ||
| --cov-config .coveragerc \ | ||
| --cov-report=xml:coverage.xml | ||
|
|
||
| - name: Save pull request number for downstream coverage upload | ||
| run: | | ||
| mkdir -p pr-metadata | ||
| echo "${{ github.event.pull_request.number }}" > pr-metadata/pr_number.txt | ||
|
|
||
| - name: Upload test and coverage artifacts | ||
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 | ||
| with: | ||
| name: ci-test-reports | ||
| path: coverage.xml | ||
| if-no-files-found: error | ||
|
|
||
| - name: Upload pull request metadata artifact | ||
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 | ||
| with: | ||
| name: pr-metadata | ||
| path: pr-metadata/pr_number.txt | ||
| if-no-files-found: error | ||
|
|
||
| publish_to_testpypi: | ||
| name: Publish to TestPyPI | ||
| runs-on: ubuntu-latest | ||
| needs: | ||
| - code_quality | ||
| - test | ||
| if: > | ||
| (github.event_name == 'push' && github.ref == 'refs/heads/staging') || | ||
| (github.event_name == 'workflow_dispatch' && github.event.inputs.publish_target == 'testpypi') | ||
| environment: staging | ||
| permissions: | ||
| contents: read | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 | ||
| with: | ||
| python-version: ${{ env.PYTHON_RUNTIME_VERSION }} | ||
| cache: pip | ||
|
|
||
| - name: Build and publish package to TestPyPI | ||
| env: | ||
| TWINE_USERNAME: ${{ secrets.TEST_PYPI_USERNAME }} | ||
| TWINE_PASSWORD: ${{ secrets.TEST_PYPI_PASSWORD }} | ||
| run: | | ||
| python -m pip install --upgrade pip setuptools wheel twine | ||
| python setup.py sdist bdist_wheel | ||
| python -m twine upload \ | ||
| --repository-url https://test.pypi.org/legacy/ \ | ||
| dist/* | ||
|
|
||
| publish_to_pypi: | ||
| name: Publish to PyPI | ||
| runs-on: ubuntu-latest | ||
| needs: | ||
| - code_quality | ||
| - test | ||
| if: startsWith(github.ref, 'refs/tags/') | ||
| environment: production | ||
| permissions: | ||
| contents: read | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 | ||
| with: | ||
| python-version: ${{ env.PYTHON_RUNTIME_VERSION }} | ||
| cache: pip | ||
|
|
||
| - name: Build and publish package to PyPI | ||
| env: | ||
| TWINE_USERNAME: __token__ | ||
| TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | ||
| run: | | ||
| python -m pip install --upgrade pip setuptools wheel twine | ||
| python setup.py sdist bdist_wheel | ||
| python -m twine upload dist/* | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| name: upload-coverage | ||
|
|
||
| # Runs after ci-cd completes — in the BASE repo's security context so | ||
| # CODECOV_TOKEN is always available, including for fork PRs. | ||
| on: | ||
| workflow_run: | ||
| workflows: [ci-cd] | ||
| types: [completed] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| actions: read | ||
| statuses: write | ||
|
|
||
| jobs: | ||
| upload_coverage: | ||
| name: Upload coverage to Codecov | ||
| runs-on: ubuntu-latest | ||
| if: github.event.workflow_run.conclusion == 'success' | ||
|
|
||
| steps: | ||
| - name: Checkout repository (Codecov CLI reads codecov.yml from default branch) | ||
| uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 | ||
| with: | ||
| ref: ${{ github.event.repository.default_branch }} | ||
| fetch-depth: 1 | ||
| persist-credentials: false | ||
|
|
||
| - name: Download pull request metadata from triggering run | ||
| uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4 | ||
| with: | ||
| name: pr-metadata | ||
| path: pr-metadata | ||
| run-id: ${{ github.event.workflow_run.id }} | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Download test coverage artifact from triggering run | ||
| uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4 | ||
| with: | ||
| name: ci-test-reports | ||
| path: codecov-reports | ||
| run-id: ${{ github.event.workflow_run.id }} | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Resolve pull request number | ||
| id: pr | ||
| run: | | ||
| pr_number="$(tr -d '[:space:]' < pr-metadata/pr_number.txt || true)" | ||
| echo "number=${pr_number}" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Verify coverage file exists | ||
| run: test -f codecov-reports/coverage.xml | ||
|
|
||
| - name: Upload coverage to Codecov | ||
| uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4 | ||
| with: | ||
| token: ${{ secrets.CODECOV_TOKEN }} | ||
| files: codecov-reports/coverage.xml | ||
| flags: cli | ||
| disable_search: true | ||
| fail_ci_if_error: true | ||
| verbose: true | ||
| override_commit: ${{ github.event.workflow_run.head_sha }} | ||
| override_branch: ${{ github.event.workflow_run.head_branch }} | ||
| override_pr: ${{ steps.pr.outputs.number }} | ||
|
|
||
| - name: Report coverage upload status to triggering commit | ||
| if: always() | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| SHA: ${{ github.event.workflow_run.head_sha }} | ||
| CONCLUSION: ${{ job.status }} | ||
| run: | | ||
| if [ "${CONCLUSION}" = "success" ]; then | ||
| state="success" | ||
| description="Coverage uploaded to Codecov successfully." | ||
| else | ||
| state="failure" | ||
| description="Coverage upload to Codecov failed." | ||
| fi | ||
| gh api \ | ||
| --method POST \ | ||
| "/repos/${{ github.repository }}/statuses/${SHA}" \ | ||
| --field state="${state}" \ | ||
| --field description="${description}" \ | ||
| --field context="upload-coverage / Codecov" \ | ||
| --field target_url="https://app.codecov.io/gh/${{ github.repository }}" |
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
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.