Skip to content

Commit 050ca32

Browse files
authored
Merge pull request #8 from osodevops/format
Creating auto format action
2 parents 9194d47 + 25f3bab commit 050ca32

File tree

3 files changed

+85
-1
lines changed

3 files changed

+85
-1
lines changed

.github/workflows/auto-format.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Auto Format
2+
on:
3+
pull_request_target:
4+
types: [opened, synchronize]
5+
workflow_dispatch:
6+
7+
jobs:
8+
auto-format:
9+
runs-on: ubuntu-latest
10+
container: osodevops/build-harness:latest
11+
steps:
12+
# Checkout the pull request branch
13+
# "An action in a workflow run can’t trigger a new workflow run. For example, if an action pushes code using
14+
# the repository’s GITHUB_TOKEN, a new workflow will not run even when the repository contains
15+
# a workflow configured to run when push events occur."
16+
# However, using a personal access token will cause events to be triggered.
17+
# We need that to ensure a status gets posted after the auto-format commit.
18+
# We also want to trigger tests if the auto-format made no changes.
19+
- uses: actions/checkout@v2
20+
if: github.event.pull_request.state == 'open'
21+
name: Privileged Checkout
22+
with:
23+
token: ${{ secrets.TOPBOT_PUBLIC_REPO_ACCESS_TOKEN }}
24+
repository: ${{ github.event.pull_request.head.repo.full_name }}
25+
# Check out the PR commit, not the merge commit
26+
# Use `ref` instead of `sha` to enable pushing back to `ref`
27+
ref: ${{ github.event.pull_request.head.ref }}
28+
29+
# Do all the formatting stuff
30+
- name: Auto Format
31+
if: github.event.pull_request.state == 'open'
32+
shell: bash
33+
env:
34+
GITHUB_TOKEN: "${{ secrets.TOPBOT_PUBLIC_REPO_ACCESS_TOKEN }}"
35+
run: make BUILD_HARNESS_PATH=/build-harness PACKAGES_PREFER_HOST=true -f /build-harness/templates/Makefile.build-harness pr/readme/host
36+
37+
# Commit changes (if any) to the PR branch
38+
- name: Commit changes to the PR branch
39+
if: github.event.pull_request.state == 'open'
40+
shell: bash
41+
id: commit
42+
env:
43+
SENDER: ${{ github.event.sender.login }}
44+
run: |
45+
set -x
46+
output=$(git diff --name-only)
47+
48+
if [ -n "$output" ]; then
49+
echo "Changes detected. Pushing to the PR branch"
50+
git config --global user.name 'osotopbot'
51+
git config --global user.email '[email protected]'
52+
git add -A
53+
git commit -m "Auto Format"
54+
# Prevent looping by not pushing changes in response to changes from cloudpossebot
55+
[[ $SENDER == "osotopbot" ]] || git push
56+
# Set status to fail, because the push should trigger another status check,
57+
# and we use success to indicate the checks are finished.
58+
printf "::set-output name=%s::%s\n" "changed" "true"
59+
exit 1
60+
else
61+
printf "::set-output name=%s::%s\n" "changed" "false"
62+
echo "No changes detected"
63+
fi

.gitignore

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1+
# Compiled files
2+
*.tfstate
3+
*.tfstate.backup
4+
5+
# Module directory
6+
.terraform
17
.idea
8+
*.iml
9+
10+
.build-harness
11+
build-harness
12+
213
sensitive-*
314
identity
415
identity.pub
5-
known_hosts
16+
known_hosts

makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
SHELL := /bin/bash
2+
3+
# List of targets the `readme` target should call before generating the readme
4+
export README_DEPS ?= docs/targets.md
5+
6+
-include $(shell curl -sSL -o .build-harness "https://raw.githubusercontent.com/osodevops/build-harness/master/templates/Makefile.build-harness"; echo .build-harness)
7+
8+
## Lint terraform code
9+
lint:
10+
$(SELF) terraform/install terraform/get-modules terraform/get-plugins terraform/lint terraform/validate

0 commit comments

Comments
 (0)