Skip to content
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

chore: disable terraform-docs push when on forks and sign commit #150

Merged
merged 2 commits into from
Apr 25, 2024
Merged
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
32 changes: 31 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ on:
jobs:
ci:
runs-on: ubuntu-latest
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write

steps:
# Setup dependencies
- uses: actions/checkout@v4
Expand All @@ -28,11 +33,36 @@ jobs:

# Terraform-docs
- uses: terraform-docs/[email protected]
id: terraform-docs
with:
working-dir: .
output-file: README.md
output-method: inject
fail-on-diff: true
args: --lockfile=false
git-push: "true" # automatically push the changes to the branch
git-push: 'false'

# Push Terraform-docs changes
- uses: planetscale/[email protected]
# Run this step even if previous steps fails (there are changes to commit)
# but skip when on forks
if: ${{ !cancelled() && github.repository_owner == 'runatlantis' }}
with:
commit_message: "terraform-docs: automated action"
repo: ${{ github.repository }}
branch: ${{ github.head_ref || github.ref_name }}
file_pattern: 'README.md'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Print instructions to run terraform-docs locally if changes are needed and workflow is running on fork
- if: ${{ !cancelled() && github.repository_owner != 'runatlantis' && steps.terraform-docs.outputs.num_changed > 0 }}
run: |
echo '### Please run terraform-docs locally and commit the changes:' >> $GITHUB_STEP_SUMMARY
echo '' >> $GITHUB_STEP_SUMMARY
echo '```sh' >> $GITHUB_STEP_SUMMARY
echo 'docker run --rm --volume "$(pwd):/terraform-docs" -u $(id -u) quay.io/terraform-docs/terraform-docs:0.17.0 markdown --output-file README.md --output-mode inject /terraform-docs' >> $GITHUB_STEP_SUMMARY
echo 'git add README.md' >> $GITHUB_STEP_SUMMARY
echo 'git commit --amend --no-edit' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo '' >> $GITHUB_STEP_SUMMARY