Skip to content

Add domchekr.com.domaincheck.json template #114

Add domchekr.com.domaincheck.json template

Add domchekr.com.domaincheck.json template #114

name: Lint Domain Connect Templates
#version: 2024-05-10 v1
on:
pull_request_target:
branches:
- master
merge_group:
branches:
- master
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Setup refs
id: setup-refs
run: |
echo "base_sha=${{ github.event.pull_request.base.sha }}${{ github.event.merge_group.base_sha }}" >> "$GITHUB_OUTPUT"
echo "head_sha=${{ github.event.pull_request.head.sha }}${{ github.event.merge_group.head_sha }}" >> "$GITHUB_OUTPUT"
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 2
ref: ${{ steps.setup-refs.outputs.head_sha }}
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Get all changed json files
id: changed-json-files
uses: tj-actions/changed-files@v42
with:
files: |
**.json
- name: Print all changed json files
if: steps.changed-json-files.outputs.any_changed == 'true'
env:
ALL_CHANGED_FILES: ${{ steps.changed-json-files.outputs.all_changed_files }}
run: |
for file in ${ALL_CHANGED_FILES}; do
echo "$file was changed"
done
- name: Check all modified json files for version update
id: check-version-bump-needed
if: steps.changed-json-files.outputs.modified_files_count > 0
env:
ALL_MODIFIED_FILES: ${{ steps.changed-json-files.outputs.modified_files }}
run: |
echo "version_bump_check<<EOF" >> $GITHUB_ENV
echo "version_bump_check=0" >> "$GITHUB_OUTPUT"
echo "Base: ${{ steps.setup-refs.outputs.base_sha }}"
echo "Head: ${{ steps.setup-refs.outputs.head_sha }}"
for file in ${ALL_MODIFIED_FILES}; do
echo "$file was modified"
echo "File diff $file:"
git diff -U0 ${{ steps.setup-refs.outputs.base_sha }}..${{ steps.setup-refs.outputs.head_sha }} -- $file
echo "Check version field diff:"
if ! git diff -U0 ${{ steps.setup-refs.outputs.base_sha }}..${{ steps.setup-refs.outputs.head_sha }} -- $file | grep "version"; then
echo "No version update detected!"
echo "$file" >> $GITHUB_ENV
echo "version_bump_check=1" >> "$GITHUB_OUTPUT"
fi
done
echo "EOF" >> $GITHUB_ENV
- name: Comment PR with version check result
if: steps.check-version-bump-needed.outputs.version_bump_check == 1 && github.event_name == 'pull_request_target'
uses: thollander/actions-comment-pull-request@v2
with:
message: |
Version bump needed for the files:
```
${{ env.version_bump_check }}
```
comment_tag: version_bump
- name: Remove comment PR with version check result if not needed
if: steps.check-version-bump-needed.outputs.version_bump_check != 1 && github.event_name == 'pull_request_target'
uses: thollander/actions-comment-pull-request@v2
with:
message: "Version bump not needed"
mode: delete
create_if_not_exists: false
comment_tag: version_bump
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '^1.16'
- name: Install dc-template-linter
run: |
go install github.com/Domain-Connect/dc-template-linter@latest
echo `go env GOPATH`/bin
- name: Lint changed Templates
if: steps.changed-json-files.outputs.any_changed == 'true'
id: linter-output
env:
ALL_CHANGED_FILES: ${{ steps.changed-json-files.outputs.all_changed_files }}
run: |
echo "linter_error=0" >> "$GITHUB_OUTPUT"
echo "linter_output<<EOF" >> $GITHUB_ENV
for file in ${ALL_CHANGED_FILES}; do
echo "Linter result for $file" >> $GITHUB_ENV
`go env GOPATH`/bin/dc-template-linter -loglevel info $file 2>> $GITHUB_ENV || true
if ! `go env GOPATH`/bin/dc-template-linter -tolerate warn $file; then
echo "linter_error=1" >> "$GITHUB_OUTPUT"
echo "Linter error for $file"
`go env GOPATH`/bin/dc-template-linter -loglevel error $file || true
fi
done
echo "EOF" >> $GITHUB_ENV
- name: Comment PR with linter error result
if: steps.linter-output.outputs.linter_error == 1 && github.event_name == 'pull_request_target'
uses: thollander/actions-comment-pull-request@v2
with:
message: |
Linter error:
```
${{ env.linter_output }}
```
comment_tag: linter
- name: Comment PR with linter OK result
if: steps.linter-output.outputs.linter_error != 1 && github.event_name == 'pull_request_target'
uses: thollander/actions-comment-pull-request@v2
with:
message: |
Linter OK:
```
${{ env.linter_output }}
```
comment_tag: linter
- name: Fail job if version check or linter fails
if: steps.linter-output.outputs.linter_error == 1 || steps.check-version-bump-needed.outputs.version_bump_check == 1
run: exit 1