-
Notifications
You must be signed in to change notification settings - Fork 0
refactor(test): extract Codecov logic to dedicated action with config fixes #358
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
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e7dad5a
Initial plan
Copilot da65e4e
fix(test): add curl configuration fix for unexpanded SSL_CERT_FILE va…
Copilot d4a9643
fix: remove unused os module import from curl configuration fix
Copilot 2d0587f
refactor: move Codecov logic to dedicated action with dependency cleanup
Copilot d245700
fix: remove container input and always check for missing deps
Copilot 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 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,37 @@ | ||
| # Codecov Action | ||
|
|
||
| Action to upload coverage to Codecov with support for container mode. | ||
|
|
||
| ## Overview | ||
|
|
||
| This action handles uploading code coverage to Codecov. When running in container mode, it automatically installs required dependencies (Git, cURL, gnupg) via pkgxdev, fixes configuration issues with unexpanded environment variables, uploads coverage, and then cleans up the installed dependencies. | ||
|
|
||
| ## Usage | ||
|
|
||
| ```yaml | ||
| - uses: hoverkraft-tech/ci-github-nodejs/actions/codecov@main | ||
| with: | ||
| # Working directory where coverage files are located. | ||
| # Can be absolute or relative to the repository root. | ||
| # | ||
| # Default: `.` | ||
| working-directory: . | ||
|
|
||
| # Whether running in container mode (installs dependencies if needed) | ||
| # Default: `false` | ||
| container: "false" | ||
| ``` | ||
|
|
||
| ## Inputs | ||
|
|
||
| | **Input** | **Description** | **Required** | **Default** | | ||
| | ----------------------- | ------------------------------------------------------------------- | ------------ | ----------- | | ||
| | **`working-directory`** | Working directory where coverage files are located. | **false** | `.` | | ||
| | **`container`** | Whether running in container mode (installs dependencies if needed) | **false** | `false` | | ||
|
|
||
| ## Features | ||
|
|
||
| - **Automatic dependency management**: In container mode, automatically detects and installs missing dependencies (Git, cURL, gnupg) using pkgxdev | ||
| - **Configuration fixes**: Automatically fixes pkgxdev configuration issues with unexpanded environment variables in gpgconf.ctl and .curlrc files | ||
| - **Cleanup**: Uninstalls dependencies after Codecov upload is complete | ||
| - **OIDC support**: Uses OIDC authentication with Codecov for secure uploads |
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,128 @@ | ||
| name: "Codecov" | ||
| description: "Action to upload coverage to Codecov with support for container mode" | ||
| author: hoverkraft | ||
| branding: | ||
| icon: upload-cloud | ||
| color: blue | ||
|
|
||
| inputs: | ||
| working-directory: | ||
| description: | | ||
| Working directory where coverage files are located. | ||
| Can be absolute or relative to the repository root. | ||
| required: false | ||
| default: "." | ||
| container: | ||
| description: "Whether running in container mode (installs dependencies if needed)" | ||
| required: false | ||
| default: "false" | ||
|
|
||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| # Check and install dependencies for codecov in container mode | ||
| - name: Check Codecov dependencies | ||
| if: inputs.container == 'true' | ||
neilime marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| id: check-codecov-deps | ||
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | ||
| with: | ||
| script: | | ||
| // Check which dependencies are missing | ||
| const deps = {"git": "git", "curl": "curl", "gpg": "gnupg.org"}; | ||
| const missingDeps = []; | ||
|
|
||
| for (const [dep, pkg] of Object.entries(deps)) { | ||
| try { | ||
| await io.which(dep, true); | ||
| } catch { | ||
| missingDeps.push(pkg); | ||
| } | ||
| } | ||
|
|
||
| if (missingDeps.length > 0) { | ||
| core.setOutput('missing-deps', missingDeps.join(' ')); | ||
| } | ||
|
|
||
| - name: Install missing Codecov dependencies | ||
| if: steps.check-codecov-deps.outputs.missing-deps | ||
| uses: pkgxdev/setup@f211ee4db3110b42e5a156282372527e7c1ed723 # v4.0.0 | ||
| with: | ||
| +: ${{ steps.check-codecov-deps.outputs.missing-deps }} | ||
|
|
||
| # Fix pkgxdev gnupg's gpgconf.ctl which contains unexpanded environment variables | ||
| - name: Fix GPG configuration | ||
| if: contains(steps.check-codecov-deps.outputs.missing-deps, 'gnupg.org') | ||
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | ||
| with: | ||
| script: | | ||
| const fs = require('node:fs'); | ||
| const path = require('node:path'); | ||
| const os = require('node:os'); | ||
|
|
||
| // Find and remove the malformed gpgconf.ctl file that contains unexpanded shell variables | ||
| // The pkgxdev gnupg installs gpgconf.ctl next to the gpgconf binary | ||
| try { | ||
| const gpgconfPath = await io.which('gpgconf', false); | ||
| if (gpgconfPath) { | ||
| const gpgconfCtl = path.join(path.dirname(gpgconfPath), 'gpgconf.ctl'); | ||
| if (fs.existsSync(gpgconfCtl)) { | ||
| core.info(`Removing malformed gpgconf.ctl: ${gpgconfCtl}`); | ||
| await io.rmRF(gpgconfCtl); | ||
| } | ||
| } | ||
| } catch (error) { | ||
| core.warning(`Failed to check/remove gpgconf.ctl: ${error.message}`); | ||
| } | ||
|
|
||
| // Ensure GNUPGHOME is set up correctly | ||
| const gnupgHome = path.join(os.homedir(), '.gnupg'); | ||
| await io.mkdirP(gnupgHome); | ||
| fs.chmodSync(gnupgHome, 0o700); | ||
|
|
||
| # Fix pkgxdev curl's .curlrc which contains unexpanded environment variables | ||
| - name: Fix curl configuration | ||
| if: contains(steps.check-codecov-deps.outputs.missing-deps, 'curl') | ||
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | ||
| with: | ||
| script: | | ||
| const fs = require('node:fs'); | ||
| const path = require('node:path'); | ||
|
|
||
| // Find and fix the .curlrc file that contains unexpanded shell variables like ${SSL_CERT_FILE:-...} | ||
| // The pkgxdev curl installs .curlrc next to the curl binary | ||
| try { | ||
| const curlPath = await io.which('curl', false); | ||
| if (curlPath) { | ||
| const curlrc = path.join(path.dirname(curlPath), '.curlrc'); | ||
| if (fs.existsSync(curlrc)) { | ||
| core.info(`Removing malformed .curlrc: ${curlrc}`); | ||
| await io.rmRF(curlrc); | ||
| } | ||
| } | ||
| } catch (error) { | ||
| core.warning(`Failed to check/remove .curlrc: ${error.message}`); | ||
| } | ||
|
|
||
| - name: 📊 Upload coverage to Codecov | ||
| uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1 | ||
| with: | ||
| directory: ${{ inputs.working-directory }} | ||
| root_dir: ${{ inputs.working-directory }} | ||
| working-directory: ${{ inputs.working-directory }} | ||
| use_oidc: true | ||
| disable_telem: true | ||
| fail_ci_if_error: false | ||
|
|
||
| # Uninstall pkgxdev dependencies after codecov is done | ||
| - name: Uninstall Codecov dependencies | ||
| if: always() && steps.check-codecov-deps.outputs.missing-deps | ||
| shell: bash | ||
| env: | ||
| MISSING_DEPS: ${{ steps.check-codecov-deps.outputs.missing-deps }} | ||
| run: | | ||
| if command -v pkgx &> /dev/null; then | ||
| for dep in $MISSING_DEPS; do | ||
| echo "Uninstalling $dep..." | ||
| pkgx uninstall "$dep" 2>/dev/null || true | ||
| done | ||
| fi | ||
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
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.