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

feat: Added build summary with list of packages that were pushed #253

Merged
merged 8 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ jobs:

- name: Package test report
run: |
zip -rj TestReport.1.0.0.zip ./reports
zip -rj MyPackage.1.0.0.zip ./reports
zip -rj MyOtherPackage.1.0.0.zip ./reports

- name: Push Package to Octopus
uses: ./
Expand All @@ -74,4 +75,5 @@ jobs:
OCTOPUS_SPACE: 'Spaces-1'
with:
packages: |
TestReport.1.0.0.zip
MyPackage.1.0.0.zip
MyOtherPackage.1.0.0.zip
42 changes: 39 additions & 3 deletions __tests__/unit/octopus-cli-output-parsing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,46 @@ test('standard commandline processing', () => {
])
})

test('thing pushed successfully', () => {
w.stdline('Push successful')
describe('pushing a single package', () => {
test('using only filename', () => {
w.stdline('Pushing package: MyPackage.1.0.0.zip...')

expect(infoMessages).toEqual(['🎉 Push successful!'])
expect(infoMessages).toEqual(['📦 Pushing MyPackage.1.0.0.zip'])
})

test('using full path', () => {
w.stdline('Pushing package: /path/to/package/MyPackage.1.0.0.tar.gz...')

expect(infoMessages).toEqual(['📦 Pushing /path/to/package/MyPackage.1.0.0.tar.gz'])
})

test('successfully', () => {
w.stdline('Push successful')

expect(infoMessages).toEqual(['🎉 Push successful!'])
})
})

describe('pushing multiple packages', () => {
test('using only filename', () => {
w.stdline('Pushing package: MyPackage.1.0.0.zip...')
w.stdline('Pushing package: MyOtherPackage.1.1.0.tar.gz...')

expect(infoMessages).toEqual([
'📦 Pushing MyPackage.1.0.0.zip',
'📦 Pushing MyOtherPackage.1.1.0.tar.gz'
])
})

test('using full path', () => {
w.stdline('Pushing package: /path/to/package/MyPackage.1.0.0.tar.gz...')
w.stdline('Pushing package: /path/to/package/MyOtherPackage.1.1.0.zip...')

expect(infoMessages).toEqual([
'📦 Pushing /path/to/package/MyPackage.1.0.0.tar.gz',
'📦 Pushing /path/to/package/MyOtherPackage.1.1.0.zip'
])
})
})

test('other lines just get passed through', () => {
Expand Down
25 changes: 22 additions & 3 deletions src/octopus-cli-wrapper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { InputParameters } from './input-parameters'
import { info, setFailed } from '@actions/core'
import { info, setFailed, summary } from '@actions/core'
import { exec, ExecOptions } from '@actions/exec'

// environment variables can either be a NodeJS.ProcessEnv or a plain old object with string keys/values for testing
Expand All @@ -10,6 +10,7 @@ export class OctopusCliWrapper {
env: EnvVars
logInfo: (message: string) => void
logWarn: (message: string) => void
pushedPackages: string[] = []

constructor(
parameters: InputParameters,
Expand All @@ -23,7 +24,7 @@ export class OctopusCliWrapper {
this.logWarn = logWarn
}

stdline(line: string): void {
async stdline(line: string): Promise<void> {
if (line.length <= 0) return

if (line.includes('Octopus Deploy Command Line Tool')) {
Expand All @@ -42,9 +43,18 @@ export class OctopusCliWrapper {
return
}

if (line.includes('Pushing package:')) {
const pkg = line.replace('Pushing package: ', '').replace('...', '')
this.pushedPackages.push(pkg)

this.logInfo(`📦 Pushing ${pkg}`)
return
}

switch (line) {
case 'Push successful':
this.logInfo(`🎉 Push successful!`)
await this.createBuildSummary()
break
default:
this.logInfo(line)
Expand Down Expand Up @@ -152,13 +162,22 @@ export class OctopusCliWrapper {
return { args: launchArgs, env: launchEnv }
}

async createBuildSummary(): Promise<void> {
if (this.pushedPackages.length > 0) {
await summary
.addHeading(`🎉 Package${this.pushedPackages.length > 1 ? 's' : ''} successfully pushed to Octopus Deploy`, 3)
.addCodeBlock(this.pushedPackages.map(pkg => `📦 ${pkg}`).join('\n'))
.write()
}
}

async pushPackage(): Promise<void> {
info('🔣 Parsing inputs...')
const cliLaunchConfiguration = this.generateLaunchConfig()

const options: ExecOptions = {
listeners: {
stdline: input => this.stdline(input)
stdline: async input => await this.stdline(input)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExecOptions.stdline expects a void function, so it will ignore the Promise here and won't await it.

In practice it's probably OK, but worst-case scenario is that perhaps lines could get written out of order because it will call stdline in quick succession while previous async tasks are floating in the background?

The async part seems to be because you used the GitHub actions markdown summary builder thing.
Suggest keeping stdline as a sync function, and just collect all the stuff into an array, and call createBuildSummary later on after the process has completed.

},
env: cliLaunchConfiguration.env,
silent: true
Expand Down