Skip to content

Commit

Permalink
feat: separate scaffold-monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki-shunsuke committed Apr 6, 2022
1 parent 3fe69b0 commit a24fd65
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 45 deletions.
72 changes: 72 additions & 0 deletions create-scaffold-monorepo-pr/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Create pull request to scaffold Terraform Module
description: Create pull request to scaffold Terraform Module
inputs:
github_token:
description: 'GitHub Access Token'
required: true

module_path:
description: 'Module path'
required: true

runs:
using: composite
steps:
- run: |
echo "::error ::github_token is required"
exit 1
shell: bash
if: inputs.github_token == ''
- run: |
echo "::error ::module_path is required"
exit 1
shell: bash
if: inputs.module_path == ''
- uses: suzuki-shunsuke/tfaction/get-global-config@main
id: global-config

- run: |
echo "::set-output name=branch::scaffold-module-${MODULE_PATH/\//_}-$(date +%Y%m%dT%H%M%S)"
id: branch
shell: bash
env:
MODULE_PATH: ${{inputs.module_path}}
- run: git add "$MODULE_PATH"
shell: bash
env:
MODULE_PATH: ${{inputs.module_path}}

- run: |
git diff --cached --name-only |
xargs ghcp commit -r "$GITHUB_REPOSITORY" \
-b "${{steps.branch.outputs.branch}}" \
-m "chore($MODULE_PATH): scaffold a Terraform Module"
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
MODULE_PATH: ${{inputs.module_path}}
- run: |
opts=(-R "$GITHUB_REPOSITORY" -H "${{steps.branch.outputs.branch}}" -t "\"Scaffold a Terraform Module (${MODULE_PATH})\"" -b "\"This pull request was created by [GitHub Actions](https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID)\"")
if [ "${{steps.global-config.outputs.draft_pr}}" = "true" ]; then
opts+=( -d )
fi
echo "::notice title=Create a scaffold pull request::$ gh pr create ${opts[@]}"
if: "fromJSON(steps.global-config.outputs.skip_create_pr)"
shell: bash
env:
MODULE_PATH: ${{inputs.module_path}}
- run: |
opts=(-H "${{steps.branch.outputs.branch}}" -a "$GITHUB_ACTOR" -t "Scaffold a Terraform Module (${MODULE_PATH})" -b "@$GITHUB_ACTOR This pull request was created by [GitHub Actions workflow_dispatch event](https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID)")
if [ "${{steps.global-config.outputs.draft_pr}}" = "true" ]; then
opts+=( -d )
fi
gh pr create "${opts[@]}"
shell: bash
if: "!fromJSON(steps.global-config.outputs.skip_create_pr)"
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
MODULE_PATH: ${{inputs.module_path}}
45 changes: 0 additions & 45 deletions scaffold-module/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,48 +84,3 @@ runs:
- run: terraform-docs . > README.md
shell: bash
working-directory: ${{inputs.module_path}}

- run: |
echo "::set-output name=branch::scaffold-module-${MODULE_PATH/\//_}-$(date +%Y%m%dT%H%M%S)"
id: branch
shell: bash
env:
MODULE_PATH: ${{inputs.module_path}}
- run: git add "$MODULE_PATH"
shell: bash
env:
MODULE_PATH: ${{inputs.module_path}}

- run: |
git diff --cached --name-only |
xargs ghcp commit -r "$GITHUB_REPOSITORY" \
-b "${{steps.branch.outputs.branch}}" \
-m "chore($MODULE_PATH): scaffold a Terraform Module"
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
MODULE_PATH: ${{inputs.module_path}}
- run: |
opts=(-R "$GITHUB_REPOSITORY" -H "${{steps.branch.outputs.branch}}" -t "\"Scaffold a Terraform Module (${MODULE_PATH})\"" -b "\"This pull request was created by [GitHub Actions](https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID)\"")
if [ "${{steps.global-config.outputs.draft_pr}}" = "true" ]; then
opts+=( -d )
fi
echo "::notice title=Create a scaffold pull request::$ gh pr create ${opts[@]}"
if: "fromJSON(steps.global-config.outputs.skip_create_pr)"
shell: bash
env:
MODULE_PATH: ${{inputs.module_path}}
- run: |
opts=(-H "${{steps.branch.outputs.branch}}" -a "$GITHUB_ACTOR" -t "Scaffold a Terraform Module (${MODULE_PATH})" -b "@$GITHUB_ACTOR This pull request was created by [GitHub Actions workflow_dispatch event](https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID)")
if [ "${{steps.global-config.outputs.draft_pr}}" = "true" ]; then
opts+=( -d )
fi
gh pr create "${opts[@]}"
shell: bash
if: "!fromJSON(steps.global-config.outputs.skip_create_pr)"
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
MODULE_PATH: ${{inputs.module_path}}

0 comments on commit a24fd65

Please sign in to comment.