Skip to content

Improve example jobs in README.md #255

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
36 changes: 28 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,13 @@ steps:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
function emojiStatus(status) {
return (status === 'success') ? '✅' : '❌'
}

const output = `#### ${emojiStatus('${{ steps.fmt.outcome }}')} Terraform Format and Style 🖌
#### ${emojiStatus('${{ steps.init.outcome }}')} Terraform Initialization ⚙️
#### ${emojiStatus('${{ steps.validate.outcome }}')} Terraform Validation 🤖
<details><summary>Validation Output</summary>

\`\`\`\n
Expand All @@ -129,7 +133,7 @@ steps:

</details>

#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
#### ${emojiStatus('${{ steps.plan.outcome }}')} Terraform Plan 📖

<details><summary>Show Plan</summary>

Expand All @@ -147,6 +151,11 @@ steps:
repo: context.repo.repo,
body: output
})

const statuses = ['${{ steps.fmt.outcome }}', '${{ steps.init.outcome }}', '${{ steps.validate.outcome }}', '${{ steps.plan.outcome }}']
if (statuses.includes("failure")) {
core.setFailed("Terraform failed, check PR comment for details")
}
```

Instead of creating a new comment each time, you can also update an existing one:
Expand Down Expand Up @@ -186,6 +195,11 @@ steps:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// 0. Create helper functions
function emojiStatus(status) {
return (status === 'success') ? '✅' : '❌'
}

// 1. Retrieve existing bot comments for the PR
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
Expand All @@ -197,9 +211,9 @@ steps:
})

// 2. Prepare format of the comment
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
const output = `#### ${emojiStatus('${{ steps.fmt.outcome }}')} Terraform Format and Style 🖌
#### ${emojiStatus('${{ steps.init.outcome }}')} Terraform Initialization ⚙️
#### ${emojiStatus('${{ steps.validate.outcome }}')} Terraform Validation 🤖
<details><summary>Validation Output</summary>

\`\`\`\n
Expand All @@ -208,7 +222,7 @@ steps:

</details>

#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
#### ${emojiStatus('${{ steps.plan.outcome }}')} Terraform Plan 📖

<details><summary>Show Plan</summary>

Expand Down Expand Up @@ -236,6 +250,12 @@ steps:
body: output
})
}

// 4. Fail the workflow if one of the steps failed
const statuses = ['${{ steps.fmt.outcome }}', '${{ steps.init.outcome }}', '${{ steps.validate.outcome }}', '${{ steps.plan.outcome }}']
if (statuses.includes("failure")) {
core.setFailed("Terraform failed, check PR comment for details")
}
```

## Inputs
Expand Down