Skip to content

Commit 72da2ac

Browse files
Copilotneilime
andcommitted
fix(test): use github-script with io helpers for codecov deps check and GPG fix
Co-authored-by: neilime <314088+neilime@users.noreply.github.com>
1 parent 9ad492f commit 72da2ac

File tree

1 file changed

+53
-19
lines changed

1 file changed

+53
-19
lines changed

actions/test/action.yml

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -138,33 +138,67 @@ runs:
138138
title: "Code Coverage Report"
139139
body: ${{ steps.parse-coverage-reports.outputs.markdown }}
140140

141-
# Install dependencies for codecov in container mode
142-
- name: Install Codecov dependencies
141+
# Check and install dependencies for codecov in container mode
142+
- name: Check and install Codecov dependencies
143143
if: inputs.coverage == 'codecov' && inputs.container == 'true'
144+
id: check-codecov-deps
145+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
146+
with:
147+
script: |
148+
const path = require('node:path');
149+
150+
// Check which dependencies are missing
151+
const deps = ['git', 'curl', 'gpg'];
152+
const missingDeps = [];
153+
154+
for (const dep of deps) {
155+
try {
156+
await io.which(dep, true);
157+
core.info(`✓ ${dep} is already available`);
158+
} catch {
159+
core.info(`✗ ${dep} is not available, will be installed`);
160+
missingDeps.push(dep);
161+
}
162+
}
163+
164+
core.setOutput('missing-deps', missingDeps.join(' '));
165+
core.setOutput('needs-install', missingDeps.length > 0 ? 'true' : 'false');
166+
167+
- name: Install missing Codecov dependencies
168+
if: inputs.coverage == 'codecov' && inputs.container == 'true' && steps.check-codecov-deps.outputs.needs-install == 'true'
144169
uses: pkgxdev/setup@f211ee4db3110b42e5a156282372527e7c1ed723 # v4.0.0
145170
with:
146171
+: git curl gnupg.org
147172

148173
# Fix pkgxdev gnupg's gpgconf.ctl which contains unexpanded environment variables
149174
- name: Fix GPG configuration
150175
if: inputs.coverage == 'codecov' && inputs.container == 'true'
151-
shell: bash
152-
run: |
153-
# Find and remove the malformed gpgconf.ctl file that contains unexpanded shell variables
154-
# The pkgxdev gnupg installs gpgconf.ctl next to the gpgconf binary
155-
if command -v gpgconf >/dev/null 2>&1; then
156-
gpgconf_bin=$(command -v gpgconf)
157-
gpgconf_ctl="$(dirname "$gpgconf_bin")/gpgconf.ctl"
158-
if [ -f "$gpgconf_ctl" ]; then
159-
echo "Removing malformed gpgconf.ctl: $gpgconf_ctl"
160-
if ! rm -f "$gpgconf_ctl"; then
161-
echo "Warning: Failed to remove gpgconf.ctl, GPG may not work correctly"
162-
fi
163-
fi
164-
fi
165-
# Ensure GNUPGHOME is set up correctly
166-
mkdir -p "$HOME/.gnupg"
167-
chmod 700 "$HOME/.gnupg"
176+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
177+
with:
178+
script: |
179+
const fs = require('node:fs');
180+
const path = require('node:path');
181+
const os = require('node:os');
182+
183+
// Find and remove the malformed gpgconf.ctl file that contains unexpanded shell variables
184+
// The pkgxdev gnupg installs gpgconf.ctl next to the gpgconf binary
185+
try {
186+
const gpgconfPath = await io.which('gpgconf', false);
187+
if (gpgconfPath) {
188+
const gpgconfCtl = path.join(path.dirname(gpgconfPath), 'gpgconf.ctl');
189+
if (fs.existsSync(gpgconfCtl)) {
190+
core.info(`Removing malformed gpgconf.ctl: ${gpgconfCtl}`);
191+
await io.rmRF(gpgconfCtl);
192+
}
193+
}
194+
} catch (error) {
195+
core.warning(`Failed to check/remove gpgconf.ctl: ${error.message}`);
196+
}
197+
198+
// Ensure GNUPGHOME is set up correctly
199+
const gnupgHome = path.join(os.homedir(), '.gnupg');
200+
await io.mkdirP(gnupgHome);
201+
fs.chmodSync(gnupgHome, 0o700);
168202
169203
- name: 📊 Upload coverage to Codecov
170204
if: always() && inputs.coverage == 'codecov'

0 commit comments

Comments
 (0)