v1.0.0 #10
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Sentinel | |
on: # yamllint disable-line rule:truthy | |
pull_request: | |
branches: | |
- '*' # matches every branch that doesn't contain a '/' | |
- '*/*' # matches every branch containing a single '/' | |
- '**' # matches every branch | |
paths: | |
- '**.tf' | |
- '**.hcl' | |
- '**.sentinel' | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
job: | |
name: Sentinel Test | |
runs-on: ubuntu-latest | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
steps: | |
- name: Branch | |
id: branch | |
run: echo "branch=${GITHUB_HEAD_REF}" >> "$GITHUB_OUTPUT" | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ steps.branch.outputs.branch }} | |
- name: 'Sentinel Format' | |
id: fmt | |
uses: ConseilsTI/GitHubAction-SentinelFormat@v1.0.1 | |
with: | |
check: false | |
delete_comment: false | |
- name: Git Push | |
if: ${{ steps.fmt.outputs.exitcode == 2 }} | |
run: | | |
echo "INFO | Pushing file(s) to the repository." | |
{ | |
git config user.name "GitHub Action" | |
git config user.email "notifications@github.com" | |
git add -A | |
git commit -m "Automated Terraform Formatting" | |
git push -u origin ${{ steps.branch.outputs.branch }} | |
} || | |
{ | |
echo "ERROR | Unable to push file(s) to the repository." | |
} | |
echo "INFO | Adding comment to pull request." | |
accept_header="Accept: application/vnd.github.v3+json" | |
auth_header="Authorization: token ${GITHUB_TOKEN}" | |
content_header="Content-Type: application/json" | |
pr_comments_url=$(jq -r ".pull_request.comments_url" "${GITHUB_EVENT_PATH}") | |
body=":warning: New files have been pushed to the repository, you need to update your local copy of the repository." | |
pr_payload=$(echo '{}' | jq --arg body "${body}" '.body = $body') | |
{ | |
curl -sS -X POST -H "${auth_header}" -H "${accept_header}" -H "${content_header}" -d "${pr_payload}" -L "${pr_comments_url}" > /dev/null | |
} || | |
{ | |
echo "ERROR | Unable to add comment to pull request." | |
} | |
- name: 'Sentinel Test' | |
uses: hashicorp/sentinel-github-actions@master | |
with: | |
stl_actions_version: latest | |
stl_actions_subcommand: 'test' | |
stl_actions_working_dir: ./policies/global | |
stl_actions_comment: true |