Skip to content
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

Post output of action in dry-run mode as a PR comment #143

Open
lopopolo opened this issue Aug 9, 2021 · 3 comments
Open

Post output of action in dry-run mode as a PR comment #143

lopopolo opened this issue Aug 9, 2021 · 3 comments

Comments

@lopopolo
Copy link

lopopolo commented Aug 9, 2021

I currently have a dedicated workflow for running this action which is configured like this:

---
"on":
  push:
    branches:
      - trunk
    paths:
      - .github/labels.yaml
      - .github/workflows/repo-labels.yaml
  pull_request:
    branches:
      - trunk
    paths:
      - .github/labels.yaml
      - .github/workflows/repo-labels.yaml
  schedule:
    - cron: "0 0 * * TUE"
name: Create Repository Labels
jobs:
  labels:
    name: Synchronize repository labels
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Sync GitHub Issue Labels
        uses: crazy-max/ghaction-github-labeler@v3
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          yaml-file: .github/labels.yaml
          skip-delete: false
          dry-run: ${{ github.ref != 'refs/heads/trunk' }}

PRs that modify either the workflow or the labels trigger a dry run. Once merged to the main branch, the GH Action is run in live mode.

When run in dry-run mode on a PR, I'd like the option to post the output which appears in the workflow job logs as a comment on the action. I usually do this manually to make sure I didn't do any typos and the action makes the changes I expect: artichoke/docker-artichoke-nightly#44.

I don't think I can implement this myself with a action script because I can't capture the output of the labeler action.

@lopopolo
Copy link
Author

It looks like the new "job summaries" feature GitHub launched would be a great way to achieve this:

https://github.blog/2022-05-09-supercharging-github-actions-with-job-summaries/

To make it easier for Actions authors to generate Job Summaries, we’ve also added a new helper utility to the @actions/core npm package.

import * as core from '@actions/core' 
  await core.summary
  .addHeading('Test Results')
  .addCodeBlock(generateTestResults(), "js")
  .addTable([
    [{data: 'File', header: true}, {data: 'Result', header: true}],
    ['foo.js', 'Pass ✅'],
    ['bar.js', 'Fail ❌'],
    ['test.js', 'Pass ✅']
  ])
  .addLink('View staging deployment!', 'https://github.com')
  .write()

@davorpa
Copy link

davorpa commented Sep 9, 2022

It looks like the new "job summaries" feature GitHub launched would be a great way to achieve this:

github.blog/2022-05-09-supercharging-github-actions-with-job-summaries

To make it easier for Actions authors to generate Job Summaries, we’ve also added a new helper utility to the @actions/core npm package.

import * as core from '@actions/core' 
  await core.summary
  .addHeading('Test Results')
  .addCodeBlock(generateTestResults(), "js")
  .addTable([
    [{data: 'File', header: true}, {data: 'Result', header: true}],
    ['foo.js', 'Pass ✅'],
    ['bar.js', 'Fail ❌'],
    ['test.js', 'Pass ✅']
  ])
  .addLink('View staging deployment!', 'https://github.com[](https://github.com)')
  .write()

@lopopolo, have a report of what actions does is always great but for this we need first to export the results as action output

This is not coded yet as we can see in

async run(): Promise<void> {
let hasError = false;
for (const label of await this.labels) {
switch (label.ghaction_status) {
case LabelStatus.Exclude: {
this.logInfo(`${label.ghaction_log}`);
break;
}
case LabelStatus.Create: {
this.logInfo(`${label.ghaction_log}`);
if (this.dryRun) {
break;
}
hasError = !(await this.createLabel(label));
break;
}
case LabelStatus.Update: {
this.logInfo(`${label.ghaction_log}`);
if (this.dryRun) {
break;
}
hasError = !(await this.updateLabel(label));
break;
}
case LabelStatus.Rename: {
this.logInfo(`${label.ghaction_log}`);
if (this.dryRun) {
break;
}
hasError = !(await this.renameLabel(label));
break;
}
case LabelStatus.Delete: {
if (this.skipDelete) {
this.logInfo(`⛔️ Skipping delete for '${label.name}' (inputs.skipDelete on)`);
break;
}
this.logInfo(`${label.ghaction_log}`);
if (this.dryRun) {
break;
}
hasError = !(await this.deleteLabel(label));
break;
}
case LabelStatus.Skip: {
this.logInfo(`${label.ghaction_log}`);
break;
}
case LabelStatus.Error: {
this.logError(`${label.ghaction_log}`);
hasError = true;
break;
}
default: {
this.logError(`🚫 '${label.name}' not processed`);
hasError = true;
break;
}
}
}
if (hasError) {
throw new Error('Errors have occurred. Please check generated annotations.');
}
}

Return the label record and the operation result is what you expect?

@shriduttkothari
Copy link

any update on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants