@@ -13,6 +13,10 @@ inputs:
1313 description : ' Identifies type of comment adding (e.g. lint)'
1414 required : false
1515 default : ' '
16+ post-target :
17+ description : " Where to post the results — valid options: 'both', 'github-step-summary', 'pull-request'"
18+ required : false
19+ default : ' both'
1620
1721runs :
1822 using : ' composite'
@@ -40,33 +44,44 @@ runs:
4044
4145 try {
4246 // Get the inputs passed to the GitHub Action
43- console.info('Received Input Label:', "${{ inputs.label }}");
47+ let postTarget = "${{ inputs['post-target'] }}".toLowerCase().trim();
48+
49+ // Validate postTarget
50+ const validOptions = ['both', 'github-step-summary', 'pull-request'];
51+ if (!validOptions.includes(postTarget)) {
52+ console.warn(`⚠️ Invalid post-target value '${postTarget}'. Defaulting to 'both'.`);
53+ postTarget = 'both';
54+ }
55+ console.info("Received Input Label:", "${{ inputs.label }}");
56+ console.info("Received Input post-target:", postTarget);
4457 console.info("Reading ext_script.js...");
4558 const scriptContent = fs.readFileSync('ext_script.js', 'utf8');
4659
4760 // Dynamically execute the input script provided in GitHub Action
48- console.info('Executing script...');
61+ console.info('🚀 Executing user script...');
4962 // passing github, and context to function
5063 const func = new Function('github', 'context', 'core', 'glob', 'io', 'exec', 'require', `
5164 return (async () => {
5265 ${scriptContent}
5366 })();
5467 `);
5568 const body = await func(github, context, core, glob, io, exec, require);
56- console.info('Executed script successfully');
69+ console.info('✅ Executed user script successfully. ');
5770
5871 // Output to GITHUB_STEP_SUMMARY
59- const summaryPath = process.env.GITHUB_STEP_SUMMARY;
60- if (summaryPath) {
61- fs.appendFileSync(summaryPath, '\n---\n');
62- fs.appendFileSync(summaryPath, body);
63- console.info(`📝 Appended ${{ inputs.label }} results to GITHUB_STEP_SUMMARY`);
64- } else {
65- console.warn('⚠️ GITHUB_STEP_SUMMARY is not defined.');
72+ if (postTarget === 'both' || postTarget === 'github-step-summary') {
73+ const summaryPath = process.env.GITHUB_STEP_SUMMARY;
74+ if (summaryPath) {
75+ fs.appendFileSync(summaryPath, '\n---\n');
76+ fs.appendFileSync(summaryPath, body);
77+ console.info(`📝 Appended ${{ inputs.label }} results to GITHUB_STEP_SUMMARY`);
78+ } else {
79+ console.warn('⚠️ GITHUB_STEP_SUMMARY is not defined.');
80+ }
6681 }
6782
6883 // Create comment on the pull request (if applicable)
69- if (context.eventName === 'pull_request') {
84+ if ((postTarget === 'both' || postTarget === 'pull-request') && context.eventName === 'pull_request') {
7085 await github.rest.issues.createComment({
7186 owner: context.repo.owner,
7287 repo: context.repo.repo,
7590 });
7691 console.info(`💬 Commented ${{ inputs.label }} results on PR`);
7792 }
93+
94+ if (postTarget === 'pull-request' && context.eventName !== 'pull_request') {
95+ console.info('⚠️ post-target is set to pull-request, but this workflow did not run on a pull_request event.');
96+ }
7897 } catch (error) {
7998 console.error(`❌ Error processing ${{ inputs.label }} results:`, error);
8099 }
0 commit comments