https://github.com/dawitnida/packer-validate-action
Packer Validate GitHub Action
https://github.com/dawitnida/packer-validate-action
git github-action github-actions hashicorp hashicorp-packer packer packer-template packer-validate
Last synced: 10 months ago
JSON representation
Packer Validate GitHub Action
- Host: GitHub
- URL: https://github.com/dawitnida/packer-validate-action
- Owner: dawitnida
- License: apache-2.0
- Created: 2019-04-07T10:33:04.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-10-27T22:01:29.000Z (over 5 years ago)
- Last Synced: 2024-03-14T23:46:26.192Z (over 2 years ago)
- Topics: git, github-action, github-actions, hashicorp, hashicorp-packer, packer, packer-template, packer-validate
- Language: Shell
- Size: 568 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Packer Validate Action
These is unofficial Packer [GitHub Actions][github-actions] which allows you to run packer validation and inspection on
pull requests to review Packer template changes and potentially build on pull merge.
Check out the [official Packer documentation][packer-doc] for further reference.
Runs `packer validate *.json` on pull request to validate the syntax and configuration of a template file in a directory
If the validation fails, it will print out error as pull request comment.
Check out the [packer validate command][packer-validate-doc] for further reference.
## Usage
### YAML style
To configure the action simply add the following lines to your .github/workflows/packer-validate.yml workflow file:
```
name: Validate packer template file in a directory
on:
pull_request:
jobs:
packer_validate:
runs-on: hashicorp/packer:1.6.4
steps:
- name: Packer validate template-y without argument
uses: dawitnida/packer-github-actions/validate@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TEMPLATE_FILE_NAME: ${{ env.TEMPLATE_FILE_NAME }}
```
### Legacy
To check this in action, please check [Packer actions demo project][packer-actions-demo] with a collection
of sample packer template files.
Variables
- `PACKER_ACTION_WORKING_DIR` : Working directory
- `TEMPLATE_FILE_NAME` : Packer template file
- `ACTION_COMMENT` : Enable/Disable PR comment from validate result
```
workflow "packer validate docker-image-template" {
resolves = "packer-validate-docker-image-template"
on = "pull_request"
}
action "filter-open-synced-pr" {
uses = "actions/bin/filter@master"
args = "action 'opened|synchronize'"
}
# For single template (eg. dockers dir contains *.json template)
action "packer-validate-docker-image-template" {
uses = "dawitnida/packer-validate-action@master"
needs = "filter-open-synced-pr"
secrets = [
"GITHUB_TOKEN",
]
env = {
TEMPLATE_FILE_NAME = "*.json"
PACKER_ACTION_WORKING_DIR = "dockers"
}
}
workflow "packer validate template-x with var-file" {
resolves = "packer-validate-template-x"
on = "pull_request"
}
# For specific template file (eg. packer-template-x.json) with var-file (global-vars.json) arg
action "packer-validate-template-x" {
uses = "dawitnida/packer-validate-action@master"
needs = "filter-open-synced-pr"
secrets = [
"GITHUB_TOKEN",
]
args = [
"-var-file=global-vars.json",
]
env = {
TEMPLATE_FILE_NAME = "packer-template-x.json"
}
}
workflow "packer validate template-y without arg" {
resolves = "packer-validate-template-y"
on = "pull_request"
}
# For specific template file (eg. packer-template-y.json) without any args
action "packer-validate-template-y" {
uses = "dawitnida/packer-validate-action@master"
needs = "filter-open-synced-pr"
secrets = [
"GITHUB_TOKEN",
]
env = {
TEMPLATE_FILE_NAME = "packer-template-y.json"
}
}
```
**Figure 1.** *Packer validate without args failed with a comment*

**Figure 2.** *Packer validate success & failed outputs*

**Figure 3.** *Packer validate complete check list diagram*

## License
The Dockerfile and associated scripts and documentation in this project are released under the [Apache-2.0 License](LICENSE).
### Author
[Dawit Nida](https://github.com/dawitnida)
[packer-validate-doc]:
[packer-actions-demo]:
[github-actions]:
[packer-doc]: