|
| 1 | +name: "Codecov" |
| 2 | +description: "Action to upload coverage to Codecov with support for container mode" |
| 3 | +author: hoverkraft |
| 4 | +branding: |
| 5 | + icon: upload-cloud |
| 6 | + color: blue |
| 7 | + |
| 8 | +inputs: |
| 9 | + working-directory: |
| 10 | + description: | |
| 11 | + Working directory where coverage files are located. |
| 12 | + Can be absolute or relative to the repository root. |
| 13 | + required: false |
| 14 | + default: "." |
| 15 | + container: |
| 16 | + description: "Whether running in container mode (installs dependencies if needed)" |
| 17 | + required: false |
| 18 | + default: "false" |
| 19 | + |
| 20 | +runs: |
| 21 | + using: "composite" |
| 22 | + steps: |
| 23 | + # Check and install dependencies for codecov in container mode |
| 24 | + - name: Check Codecov dependencies |
| 25 | + if: inputs.container == 'true' |
| 26 | + id: check-codecov-deps |
| 27 | + uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 |
| 28 | + with: |
| 29 | + script: | |
| 30 | + // Check which dependencies are missing |
| 31 | + const deps = {"git": "git", "curl": "curl", "gpg": "gnupg.org"}; |
| 32 | + const missingDeps = []; |
| 33 | +
|
| 34 | + for (const [dep, pkg] of Object.entries(deps)) { |
| 35 | + try { |
| 36 | + await io.which(dep, true); |
| 37 | + } catch { |
| 38 | + missingDeps.push(pkg); |
| 39 | + } |
| 40 | + } |
| 41 | +
|
| 42 | + if (missingDeps.length > 0) { |
| 43 | + core.setOutput('missing-deps', missingDeps.join(' ')); |
| 44 | + } |
| 45 | +
|
| 46 | + - name: Install missing Codecov dependencies |
| 47 | + if: steps.check-codecov-deps.outputs.missing-deps |
| 48 | + uses: pkgxdev/setup@f211ee4db3110b42e5a156282372527e7c1ed723 # v4.0.0 |
| 49 | + with: |
| 50 | + +: ${{ steps.check-codecov-deps.outputs.missing-deps }} |
| 51 | + |
| 52 | + # Fix pkgxdev gnupg's gpgconf.ctl which contains unexpanded environment variables |
| 53 | + - name: Fix GPG configuration |
| 54 | + if: contains(steps.check-codecov-deps.outputs.missing-deps, 'gnupg.org') |
| 55 | + uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 |
| 56 | + with: |
| 57 | + script: | |
| 58 | + const fs = require('node:fs'); |
| 59 | + const path = require('node:path'); |
| 60 | + const os = require('node:os'); |
| 61 | +
|
| 62 | + // Find and remove the malformed gpgconf.ctl file that contains unexpanded shell variables |
| 63 | + // The pkgxdev gnupg installs gpgconf.ctl next to the gpgconf binary |
| 64 | + try { |
| 65 | + const gpgconfPath = await io.which('gpgconf', false); |
| 66 | + if (gpgconfPath) { |
| 67 | + const gpgconfCtl = path.join(path.dirname(gpgconfPath), 'gpgconf.ctl'); |
| 68 | + if (fs.existsSync(gpgconfCtl)) { |
| 69 | + core.info(`Removing malformed gpgconf.ctl: ${gpgconfCtl}`); |
| 70 | + await io.rmRF(gpgconfCtl); |
| 71 | + } |
| 72 | + } |
| 73 | + } catch (error) { |
| 74 | + core.warning(`Failed to check/remove gpgconf.ctl: ${error.message}`); |
| 75 | + } |
| 76 | +
|
| 77 | + // Ensure GNUPGHOME is set up correctly |
| 78 | + const gnupgHome = path.join(os.homedir(), '.gnupg'); |
| 79 | + await io.mkdirP(gnupgHome); |
| 80 | + fs.chmodSync(gnupgHome, 0o700); |
| 81 | +
|
| 82 | + # Fix pkgxdev curl's .curlrc which contains unexpanded environment variables |
| 83 | + - name: Fix curl configuration |
| 84 | + if: contains(steps.check-codecov-deps.outputs.missing-deps, 'curl') |
| 85 | + uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 |
| 86 | + with: |
| 87 | + script: | |
| 88 | + const fs = require('node:fs'); |
| 89 | + const path = require('node:path'); |
| 90 | +
|
| 91 | + // Find and fix the .curlrc file that contains unexpanded shell variables like ${SSL_CERT_FILE:-...} |
| 92 | + // The pkgxdev curl installs .curlrc next to the curl binary |
| 93 | + try { |
| 94 | + const curlPath = await io.which('curl', false); |
| 95 | + if (curlPath) { |
| 96 | + const curlrc = path.join(path.dirname(curlPath), '.curlrc'); |
| 97 | + if (fs.existsSync(curlrc)) { |
| 98 | + core.info(`Removing malformed .curlrc: ${curlrc}`); |
| 99 | + await io.rmRF(curlrc); |
| 100 | + } |
| 101 | + } |
| 102 | + } catch (error) { |
| 103 | + core.warning(`Failed to check/remove .curlrc: ${error.message}`); |
| 104 | + } |
| 105 | +
|
| 106 | + - name: 📊 Upload coverage to Codecov |
| 107 | + uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1 |
| 108 | + with: |
| 109 | + directory: ${{ inputs.working-directory }} |
| 110 | + root_dir: ${{ inputs.working-directory }} |
| 111 | + working-directory: ${{ inputs.working-directory }} |
| 112 | + use_oidc: true |
| 113 | + disable_telem: true |
| 114 | + fail_ci_if_error: false |
| 115 | + |
| 116 | + # Uninstall pkgxdev dependencies after codecov is done |
| 117 | + - name: Uninstall Codecov dependencies |
| 118 | + if: always() && steps.check-codecov-deps.outputs.missing-deps |
| 119 | + shell: bash |
| 120 | + env: |
| 121 | + MISSING_DEPS: ${{ steps.check-codecov-deps.outputs.missing-deps }} |
| 122 | + run: | |
| 123 | + if command -v pkgx &> /dev/null; then |
| 124 | + for dep in $MISSING_DEPS; do |
| 125 | + echo "Uninstalling $dep..." |
| 126 | + pkgx uninstall "$dep" 2>/dev/null || true |
| 127 | + done |
| 128 | + fi |
0 commit comments