mirror of
https://github.com/hashicorp/setup-terraform.git
synced 2025-12-17 08:52:37 +00:00
Improve example jobs
This commit is contained in:
parent
bbe167fbda
commit
6b22709ed5
1 changed files with 29 additions and 9 deletions
38
README.md
38
README.md
|
|
@ -118,9 +118,13 @@ steps:
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
script: |
|
script: |
|
||||||
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
|
function emojiStatus(status) {
|
||||||
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
|
return (status === 'success') ? '✅' : '❌'
|
||||||
#### 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>
|
<details><summary>Validation Output</summary>
|
||||||
|
|
||||||
\`\`\`\n
|
\`\`\`\n
|
||||||
|
|
@ -129,7 +133,7 @@ steps:
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
|
#### ${emojiStatus('${{ steps.plan.outcome }}')} Terraform Plan 📖
|
||||||
|
|
||||||
<details><summary>Show Plan</summary>
|
<details><summary>Show Plan</summary>
|
||||||
|
|
||||||
|
|
@ -147,6 +151,11 @@ steps:
|
||||||
repo: context.repo.repo,
|
repo: context.repo.repo,
|
||||||
body: output
|
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:
|
Instead of creating a new comment each time, you can also update an existing one:
|
||||||
|
|
@ -186,6 +195,11 @@ steps:
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
script: |
|
script: |
|
||||||
|
// 0. Create helper functions
|
||||||
|
function emojiStatus(status) {
|
||||||
|
return (status === 'success') ? '✅' : '❌'
|
||||||
|
}
|
||||||
|
|
||||||
// 1. Retrieve existing bot comments for the PR
|
// 1. Retrieve existing bot comments for the PR
|
||||||
const { data: comments } = await github.rest.issues.listComments({
|
const { data: comments } = await github.rest.issues.listComments({
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
|
|
@ -193,13 +207,13 @@ steps:
|
||||||
issue_number: context.issue.number,
|
issue_number: context.issue.number,
|
||||||
})
|
})
|
||||||
const botComment = comments.find(comment => {
|
const botComment = comments.find(comment => {
|
||||||
return comment.user.type === 'Bot' && comment.body.includes('Terraform Format and Style')
|
return comment.body.includes('Terraform Format and Style')
|
||||||
})
|
})
|
||||||
|
|
||||||
// 2. Prepare format of the comment
|
// 2. Prepare format of the comment
|
||||||
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
|
const output = `#### ${emojiStatus('${{ steps.fmt.outcome }}')} Terraform Format and Style 🖌
|
||||||
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
|
#### ${emojiStatus('${{ steps.init.outcome }}')} Terraform Initialization ⚙️
|
||||||
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
|
#### ${emojiStatus('${{ steps.validate.outcome }}')} Terraform Validation 🤖
|
||||||
<details><summary>Validation Output</summary>
|
<details><summary>Validation Output</summary>
|
||||||
|
|
||||||
\`\`\`\n
|
\`\`\`\n
|
||||||
|
|
@ -208,7 +222,7 @@ steps:
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
|
#### ${emojiStatus('${{ steps.plan.outcome }}')} Terraform Plan 📖
|
||||||
|
|
||||||
<details><summary>Show Plan</summary>
|
<details><summary>Show Plan</summary>
|
||||||
|
|
||||||
|
|
@ -236,6 +250,12 @@ steps:
|
||||||
body: output
|
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
|
## Inputs
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue