Skip to content

Commit

Permalink
chore: use shfmt (#1924)
Browse files Browse the repository at this point in the history
* chore: use shfmt

* chore: install shfmt

* style: format by prettier

* ci: rename workflow

---------

Co-authored-by: suzuki-shunsuke-app[bot] <91834585+suzuki-shunsuke-app[bot]@users.noreply.github.com>
  • Loading branch information
1 parent c565bcb commit c4884b1
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 32 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- ghalint
- build-schema
- create-pr-branch
- prettier
- format
permissions: {}
if: failure()
steps:
Expand Down Expand Up @@ -91,8 +91,8 @@ jobs:
gh_app_id: ${{secrets.APP_ID}}
gh_app_private_key: ${{secrets.APP_PRIVATE_KEY}}

prettier:
uses: ./.github/workflows/wc-prettier.yaml
format:
uses: ./.github/workflows/wc-format.yaml
permissions: {}
secrets:
gh_app_id: ${{secrets.APP_ID}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
"workflows": "write"
}
- run: npm run fmt
- run: cmdx fmt
if: |
github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork
Expand All @@ -61,7 +61,7 @@ jobs:
git diff --name-only |
xargs ghcp commit \
-r "$GITHUB_REPOSITORY" \
-m "style: format by prettier" \
-m "style: format by prettier and shfmt" \
-b "$GITHUB_HEAD_REF"
exit 1
Expand Down
25 changes: 25 additions & 0 deletions aqua-checksums.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,31 @@
"checksum": "1482935DBB13980A1CCF27BFB54500882C39EA7083FCE08977343E3AF5579006",
"algorithm": "sha256"
},
{
"id": "github_release/github.com/mvdan/sh/v3.9.0/shfmt_v3.9.0_darwin_amd64",
"checksum": "3E1AC72E91BA88CE483766E57A1AA41FA502A0F9D5A47F5F5CD3663BADCECEE4",
"algorithm": "sha256"
},
{
"id": "github_release/github.com/mvdan/sh/v3.9.0/shfmt_v3.9.0_darwin_arm64",
"checksum": "7D89694369A516B2D5A68B31F8BE2DA04C91F50FB7CDD8E41003081B814BA3E8",
"algorithm": "sha256"
},
{
"id": "github_release/github.com/mvdan/sh/v3.9.0/shfmt_v3.9.0_linux_amd64",
"checksum": "D99B06506AEE2AC9113DAEC3049922E70DC8CFFB84658E3AE512C6A6CBE101B6",
"algorithm": "sha256"
},
{
"id": "github_release/github.com/mvdan/sh/v3.9.0/shfmt_v3.9.0_linux_arm64",
"checksum": "5E511463068F3D27AE1B087FB597FB9E8AD865BE2AC501964A222A834FC1C463",
"algorithm": "sha256"
},
{
"id": "github_release/github.com/mvdan/sh/v3.9.0/shfmt_v3.9.0_windows_amd64.exe",
"checksum": "4EA136134248AC8EBBF9103370DDCD951B515A9E9BFBA903252F12FD067BB5E9",
"algorithm": "sha256"
},
{
"id": "github_release/github.com/reviewdog/reviewdog/v0.20.2/reviewdog_0.20.2_Darwin_arm64.tar.gz",
"checksum": "595D340888463796B4585FF5D1F2B0B9084E20E9A76692B4271EC92C6F4D6C64",
Expand Down
2 changes: 2 additions & 0 deletions aqua/shfmt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages:
- name: mvdan/[email protected]
11 changes: 11 additions & 0 deletions cmdx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ tasks:
exec:
- generate-schema-doc
script: |
set -eu
mkdir -p build
generate-schema-doc --expand-buttons --link-to-reused-ref schema build
- name: build
Expand Down Expand Up @@ -91,7 +92,9 @@ tasks:
description: Format with prettier
usage: Format with prettier
script: |
set -eu
npm run fmt
cmdx shfmt
- name: pinact
description: Run pinact
Expand All @@ -111,3 +114,11 @@ tasks:
script: |
set -euo pipefail
git ls-files | grep -E "\.sh$" | xargs shellcheck
- name: shfmt
shell:
- bash
- -c
script: |
set -euo pipefail
git ls-files | grep -E "\.sh$" | xargs shfmt -w -s
16 changes: 8 additions & 8 deletions create-follow-up-pr/create_commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ set -euo pipefail

follow_up_pr_file="$WORKING_DIR/.tfaction/failed-prs"
if [ ! -f "$follow_up_pr_file" ]; then
mkdir -p "$WORKING_DIR/.tfaction"
echo "# This file is created and updated by tfaction for follow up pull requests.
# You can remove this file safely." > "$follow_up_pr_file"
mkdir -p "$WORKING_DIR/.tfaction"
echo "# This file is created and updated by tfaction for follow up pull requests.
# You can remove this file safely." >"$follow_up_pr_file"
fi
echo "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/pull/$CI_INFO_PR_NUMBER" >> "$follow_up_pr_file"
echo "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/pull/$CI_INFO_PR_NUMBER" >>"$follow_up_pr_file"
ghcp commit \
-r "$GITHUB_REPOSITORY" -b "$FOLLOW_UP_BRANCH" \
-m "chore: create a commit to open follow up pull request
-r "$GITHUB_REPOSITORY" -b "$FOLLOW_UP_BRANCH" \
-m "chore: create a commit to open follow up pull request
Follow up #$CI_INFO_PR_NUMBER
$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" \
-C "$GITHUB_WORKSPACE" \
"$follow_up_pr_file"
-C "$GITHUB_WORKSPACE" \
"$follow_up_pr_file"
14 changes: 7 additions & 7 deletions create-follow-up-pr/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ bash "$GITHUB_ACTION_PATH/create_commit.sh"

pr_title="chore($TFACTION_TARGET): follow up #$CI_INFO_PR_NUMBER"

create_opts=( -H "$FOLLOW_UP_BRANCH" -t "$pr_title" )
create_opts=(-H "$FOLLOW_UP_BRANCH" -t "$pr_title")
mention=""
if ! [[ "$CI_INFO_PR_AUTHOR" =~ \[bot\] ]]; then
create_opts+=( -a "$CI_INFO_PR_AUTHOR" )
if ! [[ $CI_INFO_PR_AUTHOR =~ \[bot\] ]]; then
create_opts+=(-a "$CI_INFO_PR_AUTHOR")
mention="@$CI_INFO_PR_AUTHOR"
fi
if ! [[ "$GITHUB_ACTOR" =~ \[bot\] ]] && [ "$CI_INFO_PR_AUTHOR" != "$GITHUB_ACTOR" ]; then
create_opts+=( -a "$GITHUB_ACTOR" )
if ! [[ $GITHUB_ACTOR =~ \[bot\] ]] && [ "$CI_INFO_PR_AUTHOR" != "$GITHUB_ACTOR" ]; then
create_opts+=(-a "$GITHUB_ACTOR")
mention="@$GITHUB_ACTOR $mention"
fi
if [ "$TFACTION_DRAFT_PR" = "true" ]; then
create_opts+=( -d )
create_opts+=(-d)
fi

pr_body="$mention
Expand All @@ -38,7 +38,7 @@ Follow up #$CI_INFO_PR_NUMBER ([failed workflow]($GITHUB_SERVER_URL/$GITHUB_REPO
1. Add commits to this pull request and fix the problem if needed
1. Review and merge this pull request"

create_opts+=( -b "$pr_body" )
create_opts+=(-b "$pr_body")

follow_up_pr_url=$(gh pr create "${create_opts[@]}")
echo "::notice:: The follow up pull request: $follow_up_pr_url"
Expand Down
8 changes: 4 additions & 4 deletions create-follow-up-pr/skip_create_pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ bash "$GITHUB_ACTION_PATH/create_commit.sh"

pr_title="chore($TFACTION_TARGET): follow up #$CI_INFO_PR_NUMBER"

create_opts=( -R "$GITHUB_REPOSITORY" -H "$FOLLOW_UP_BRANCH" -t "\"$pr_title\"" -b "\"Follow up #$CI_INFO_PR_NUMBER\"" )
create_opts=(-R "$GITHUB_REPOSITORY" -H "$FOLLOW_UP_BRANCH" -t "\"$pr_title\"" -b "\"Follow up #$CI_INFO_PR_NUMBER\"")
mention=""
if ! [[ "$CI_INFO_PR_AUTHOR" =~ \[bot\] ]]; then
if ! [[ $CI_INFO_PR_AUTHOR =~ \[bot\] ]]; then
mention="@$CI_INFO_PR_AUTHOR"
fi
if ! [[ "$GITHUB_ACTOR" =~ \[bot\] ]] && [ "$CI_INFO_PR_AUTHOR" != "$GITHUB_ACTOR" ]; then
if ! [[ $GITHUB_ACTOR =~ \[bot\] ]] && [ "$CI_INFO_PR_AUTHOR" != "$GITHUB_ACTOR" ]; then
mention="@$GITHUB_ACTOR $mention"
fi
if [ "$TFACTION_DRAFT_PR" = "true" ]; then
create_opts+=( -d )
create_opts+=(-d)
fi

github-comment post \
Expand Down
2 changes: 1 addition & 1 deletion terraform-apply/download_plan_file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ github-comment exec -- gh version
pr_head_sha=$(jq -r ".head.sha" "$CI_INFO_TEMP_DIR/pr.json")

# https://github.com/suzuki-shunsuke/tfaction/pull/1570#issuecomment-1987382651
# We don't use gh run list's -c option because
# We don't use gh run list's -c option because
# 1. this requires GitHub CLI v2.40.0 or newer
# 2. we should check the latest workflow run
body=$(github-comment exec \
Expand Down
4 changes: 2 additions & 2 deletions terraform-docs/terraform-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ if ! github-comment exec \
-config "${GITHUB_ACTION_PATH}/github-comment.yaml" \
-var "tfaction_target:${TFACTION_TARGET}" \
-k terraform-docs \
-- terraform-docs $opts . > "$tempfile"; then
-- terraform-docs $opts . >"$tempfile"; then
cat "$tempfile"
rm "$tempfile"
exit 1
Expand All @@ -65,7 +65,7 @@ fi

if ! grep -q '<!-- BEGIN_TF_DOCS -->' README.md; then
# output.file is disabled
cat "$tempfile" > README.md
cat "$tempfile" >README.md
fi

rm "$tempfile"
Expand Down
6 changes: 3 additions & 3 deletions tfmigrate-apply/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -euo pipefail

if [ -z "${TFMIGRATE_EXEC_PATH:-}" ] && [ "$TF_COMMAND" != terraform ] ; then
if [ -z "${TFMIGRATE_EXEC_PATH:-}" ] && [ "$TF_COMMAND" != terraform ]; then
TFMIGRATE_EXEC_PATH=$TF_COMMAND
fi

Expand All @@ -13,13 +13,13 @@ github-comment exec \
--config "${GITHUB_ACTION_PATH}/github-comment.yaml" \
-var "tfaction_target:$TFACTION_TARGET" \
-k tfmigrate-apply -- \
tfmigrate apply 2>&1 | tee "$apply_output"
tfmigrate apply 2>&1 | tee "$apply_output"
code=$?
set -e

if [ -n "${TFACTION_DRIFT_ISSUE_NUMBER:-}" ]; then
github-comment exec \
--config "${GITHUB_ACTION_PATH}/github-comment.yaml" \
--config "${GITHUB_ACTION_PATH}/github-comment.yaml" \
-org "$TFACTION_DRIFT_ISSUE_REPO_OWNER" \
-repo "$TFACTION_DRIFT_ISSUE_REPO_NAME" \
-pr "$TFACTION_DRIFT_ISSUE_NUMBER" \
Expand Down
2 changes: 1 addition & 1 deletion tfmigrate-plan/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -euo pipefail

if [ -z "${TFMIGRATE_EXEC_PATH:-}" ] && [ "$TF_COMMAND" != terraform ] ; then
if [ -z "${TFMIGRATE_EXEC_PATH:-}" ] && [ "$TF_COMMAND" != terraform ]; then
TFMIGRATE_EXEC_PATH=$TF_COMMAND
fi

Expand Down
2 changes: 1 addition & 1 deletion update-drift-issue/post-comment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ body=$(gh api graphql -q '.data.repository.issue.comments.nodes[0].body' -F owne

job_url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"

if [[ "$body" =~ .*$job_url.* ]]; then
if [[ $body =~ .*$job_url.* ]]; then
exit 0
fi

Expand Down

0 comments on commit c4884b1

Please sign in to comment.