-
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marcin Brański
committed
Aug 27, 2020
1 parent
6f95278
commit 89f4196
Showing
5 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
WORKFLOW_TEMPLATE_DIR ?= $(BUILD_HARNESS_PATH)/templates/github-automated-workflow | ||
|
||
## Create new workflow | ||
github-automated-workflow/init: | ||
@if [ -z $(name) ]; then echo -e "Required argument "name" not present\n"; exit 1; fi | ||
@$(eval WORKFLOW_NAME := $(shell echo "`date +"%Y-%m-%d"`-$(name)")) | ||
@if [ -d $(WORKFLOW_NAME) ]; then echo "Workflow named $(WORKFLOW_NAME) already exists"; exit 1; fi | ||
@mkdir -p $(WORKFLOW_NAME) | ||
@cp $(WORKFLOW_TEMPLATE_DIR)/workflow.yaml $(WORKFLOW_NAME) | ||
@sed -i '' -e "s/__NAME__/$(name)/" $(WORKFLOW_NAME)/workflow.yaml | ||
@echo "Workflow $(WORKFLOW_NAME) created." | ||
@echo "Update $(WORKFLOW_NAME)/workflow.yaml configuration file and run workflow with 'make github-automated-workflow/configure name=$(WORKFLOW_NAME)'" | ||
|
||
# Create scripts based on yaml configuration | ||
github-automated-workflow/configure: | ||
@if [ -z $(name) ]; then echo -e "Required argument "name" not present\n"; exit 1; fi | ||
@$(eval WORKFLOW_NAME := $(shell echo "$(name)")) | ||
@if [ ! -d $(WORKFLOW_NAME) ]; then echo "Workflow named $(WORKFLOW_NAME) does not exists"; exit 1; fi | ||
@cd $(name) && gomplate --file $(WORKFLOW_TEMPLATE_DIR)/migration.sh.gotmpl --out migration.sh | ||
@cd $(name) && gomplate --file $(WORKFLOW_TEMPLATE_DIR)/Makefile.gotmpl --out Makefile | ||
@cd $(name) && gomplate --file $(WORKFLOW_TEMPLATE_DIR)/pr-body.md.gotmpl --out pr-body.md | ||
@cd $(name) && chmod a+x migration.sh | ||
@mkdir -p $(name)/log | ||
|
||
github-automated-workflow/run: | ||
@if [ -z $(name) ]; then echo -e "Required argument "name" not present\n"; exit 1; fi | ||
@$(eval WORKFLOW_NAME := $(shell echo "$(name)")) | ||
@if [ ! -d $(WORKFLOW_NAME) ]; then echo "Workflow named $(WORKFLOW_NAME) does not exists"; exit 1; fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{{ defineDatasource "config" "workflow.yaml" | regexp.Replace ".*" "" -}} | ||
WORKFLOW_TEMPLATE_DIR ?= $(BUILD_HARNESS_PATH)/templates/github-automated-workflow/ | ||
|
||
mp-init: | ||
@mp init --repo-search "{{ (ds "config").github.repository_search }}" > log/mp_init.log | ||
@mp clone >> log/mp_clone.log | ||
|
||
mp-plan: | ||
@mp plan -b {{ (ds "config").github.branch }} -m '{{ (ds "config").github.commit_message }}' -- sh -c $$PWD/migration.sh > log/mp_plan.log | ||
|
||
{{ if eq (ds "config").github.pr.enabled true -}} | ||
mp-push: | ||
echo Create PR | ||
@mp push -b pr-body.md -a {{ (ds "config").github.pr.reviewer }} > log/mp_push.log | ||
|
||
{{- if ne (len (ds "config").github.pr.labels) 0 }} | ||
echo Label PR | ||
@echo '{"labels":["{{ join (ds "config").github.pr.labels "\",\"" }}"]}' > labels.json | ||
echo 'LABELS_JSON=`cat labels.json`; cd {}; PR_NUMBER=`gh pr create 2>&1 | tail -n1 | sed "s#.*pull/##"`; echo $$LABELS_JSON | gh api -X PATCH repos/:owner/:repo/issues/$$PR_NUMBER --input -' | ||
@find . -name 'planned' -maxdepth 4 -type d -exec sh -c 'LABELS_JSON=`cat labels.json`; cd {}; PR_NUMBER=`gh pr create 2>&1 | tail -n1 | sed "s#.*pull/##"`; echo $$LABELS_JSON | gh api -X PATCH repos/:owner/:repo/issues/$$PR_NUMBER --input -' \; >> log/mp_push.log | ||
@rm labels.json | ||
{{- end }} | ||
|
||
echo Add PR reviewers TODO | ||
# https://developer.github.com/v3/pulls/review_requests/#request-reviewers-for-a-pull-request | ||
|
||
{{ if eq (ds "config").tests true }} | ||
echo Run tests | ||
@find . -name 'planned' -maxdepth 4 -type d -exec sh -c 'cd {}; gh pr review --comment -b "/test all"' \; | ||
{{ end -}} | ||
|
||
{{ end }} | ||
status: | ||
@mp status | ||
|
||
{{ if eq (ds "config").tests true -}} | ||
# Run tests with `gh` command in planned repositories | ||
tests: | ||
@find . -name 'planned' -maxdepth 4 -type d -exec sh -c 'cd {}; gh pr review --comment -b "/test all"' \; | ||
{{ end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash -e | ||
# This script was automatically generated from workflow.yaml | ||
{{ defineDatasource "config" "workflow.yaml" | regexp.Replace ".*" "" -}} | ||
{{- range $migration := (ds "config").migrations }} | ||
{{ $migration }} >> migration.log | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{{ defineDatasource "config" "workflow.yaml" | regexp.Replace ".*" "" -}} | ||
## what | ||
{{- range $element := (ds "config").github.pr.body.what }} | ||
- {{ $element }} | ||
{{- end }} | ||
|
||
## why | ||
{{- range $element := (ds "config").github.pr.body.why }} | ||
- {{ $element }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: __NAME__ | ||
|
||
github: | ||
# https://docs.github.com/en/github/searching-for-information-on-github/searching-for-repositories | ||
# all modules | ||
# repo_search: "org:cloudposse" | ||
# terraform modules | ||
repository_search: "repo:cloudposse/terraform-aws-sns-topic" | ||
|
||
branch: auto-__NAME__ | ||
commit_message: auto-__NAME__ | ||
pr: | ||
enabled: true | ||
body: | ||
what: | ||
- what | ||
why: | ||
- why | ||
reviewer: 3h4x | ||
# cloudposse/engineering | ||
|
||
labels: | ||
- auto-merge | ||
# - auto-release | ||
|
||
tests: true | ||
|
||
migrations: | ||
- make | ||
- make readme |