diff --git a/Makefile b/Makefile index a3d9d86a..33561452 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,7 @@ -export DOCKER_ORG ?= cloudposse -export DOCKER_IMAGE ?= $(DOCKER_ORG)/terraform-root-modules -export DOCKER_TAG ?= latest -export DOCKER_IMAGE_NAME ?= $(DOCKER_IMAGE):$(DOCKER_TAG) -export DOCKER_BUILD_FLAGS = -export README_DEPS ?= docs/targets.md docs/terraform.md +export README_DEPS ?= docs/targets.md -include $(shell curl -sSL -o .build-harness "https://cloudposse.tools/build-harness"; echo .build-harness) all: init deps build install run deps: @exit 0 - -build: - @make --no-print-directory docker:build - -push: - docker push $(DOCKER_IMAGE) - -run: - docker run -it ${DOCKER_IMAGE_NAME} sh diff --git a/migrate/Makefile b/migrate/Makefile index 538ade7e..b0127844 100644 --- a/migrate/Makefile +++ b/migrate/Makefile @@ -1,4 +1,3 @@ deps: brew install gh yq pip3 install yamlfix - diff --git a/migrate/git-xargs.sh b/migrate/git-xargs.sh new file mode 100755 index 00000000..0d3788b0 --- /dev/null +++ b/migrate/git-xargs.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash + +# Due to just endless problems working around `git-xargs` limitations, challenges with rate limits, +# resorting to a basic shell script that does the same thing, but with more control and less magic and no parallelism. +set -e + +migration=$1 +batch=$2 + +# Validate usage +if [[ -z "$migration" || -z "$batch" ]]; then + echo "Usage: $0 " + exit 1 +fi +curdir=$(pwd) +migration_branch="migration/${migration}" +migration_dir="migrations/${migration}" +repos="${migration_dir}/${batch}" + +# Test if the repo file exists +if [[ ! -f "$repos" ]]; then + echo "Repo file for ${batch} batch does not exist: $repos" + exit 1 +fi + +if [[ ! -d "migrations/${migration}" ]]; then + echo "Migration does not exist: $migration" + exit 1 +fi + +while IFS= read -r repo; do + if [[ $repo == \#* ]]; then + continue + fi + cd "${curdir}" + repo_name=$(basename "$repo" .git) + repo_owner=$(basename "$(dirname "$repo")") + repo_url="git@github.com:${repo_owner}/${repo_name}.git" + tmp_dir="tmp/$repo_owner/$repo_name" + + echo "Processing $repo_url" + if [[ ! -d "$tmp_dir" ]]; then + mkdir -p $(dirname "$tmp_dir") + git clone "$repo_url" "${tmp_dir}" + fi + + cd "${tmp_dir}" || exit + + # Identify the default branch + default_branch=$(git remote show origin | grep 'HEAD branch' | cut -d' ' -f5) + + git checkout "${default_branch}" + # Ensure our branch is reset to match the remote default branch, so that we can apply the migration cleanly + git reset --hard origin/${default_branch} + git pull origin "${default_branch}" + + if git rev-parse --verify "${migration_branch}" >/dev/null 2>&1; then + echo "Deleting existing ${migration_branch} branch" + git branch -D "${migration_branch}" + fi + echo "Creating ${migration_branch} branch" + git checkout -b "${migration_branch}" + + # Always start clean + git clean -fxd + + export XARGS_DRY_RUN=${XARGS_DRY_RUN:-true} + export XARGS_REPO_NAME="${repo_name}" + export XARGS_REPO_OWNER="${repo_owner}" + export MIGRATE_PATH="${curdir}" + echo "Performing migration..." + $curdir/run.sh "${migration}" + if [[ $? -ne 0 ]]; then + echo "Migration failed for ${repo}" + exit 1 + fi + +done < "${repos}" diff --git a/migrate/lib/badges.sh b/migrate/lib/badges.sh deleted file mode 100644 index 15793cb2..00000000 --- a/migrate/lib/badges.sh +++ /dev/null @@ -1,107 +0,0 @@ -function migrate_badges() { - - readme_yaml="${1:-README.yaml}" - - if [ ! -f "${readme_yaml}" ]; then - error "${readme_yaml} file not found." - fi - - export GITHUB_REPO=$(yq '.github_repo' ${readme_yaml}) - - if [ "${GITHUB_REPO}" == "null" ]; then - error "GITHUB_REPO is not set in the ${readme_yaml} file." - fi - - # image: "https://img.shields.io/github/release/cloudposse/terraform-aws-documentdb-cluster.svg" - # Action: add ?style=for-the-style - yq -ei '.badges |= map(select(.image | test("img.shields.io")).image |= (. | sub("\.svg$"; ".svg?style=for-the-badge")) ) ' ${readme_yaml} - - # image: "https://slack.cloudposse.com/badge.svg" - # Action: replace /badge.svg with /for-the-badge.svg - yq -ei '.badges |= map(select(.image | test("slack.cloudposse.com")).image |= (. | sub("/badge\.svg$"; "/for-the-badge.svg")) ) ' ${readme_yaml} - - # - name: "Codefresh Build Status" - # image: "https://g.codefresh.io/api/badges/pipeline/cloudposse/terraform-modules%2Fterraform-aws-ecs-web-app?type=cf-1" - # url: "https://g.codefresh.io/public/accounts/cloudposse/pipelines/5dbb22a15c2e97b3b73ab484" - yq -ei 'del(.badges[] | select(.name == "*Codefresh*"))' ${readme_yaml} - - # - name: "Build Status" - # image: "https://travis-ci.org/cloudposse/terraform-aws-ec2-ami-backup.svg?branch=master" - # url: "https://travis-ci.org/cloudposse/terraform-aws-ec2-ami-backup" - # Action: delete it - yq -ei 'del(.badges[] | select(.name == "*Build Status*"))' ${readme_yaml} - - # - name: "Latest Release" - # image: "https://img.shields.io/github/release/cloudposse/terraform-aws-ec2-ami-backup.svg" - # url: "https://travis-ci.org/cloudposse/terraform-aws-ec2-ami-backup/releases" - # Action: Replace it - yq -ei 'del(.badges[] | select(.name == "Latest Release"))' ${readme_yaml} - - #- name: GitHub Action Build Status - # image: https://github.com/cloudposse/terraform-aws-lambda-elasticsearch-cleanup/workflows/Lambda/badge.svg?branch=master - # url: https://github.com/cloudposse/terraform-aws-lambda-elasticsearch-cleanup/actions?query=workflow%3ALambda - yq -ei 'del(.badges[] | select(.name == "GitHub Action Build Status"))' ${readme_yaml} - - #- name: "Discourse Forum" - # image: "https://img.shields.io/discourse/https/ask.sweetops.com/posts.svg" - # url: "https://ask.sweetops.com/" - # Action: Remove it - yq -ei 'del(.badges[] | select(.name == "Discourse Forum"))' ${readme_yaml} - - - # Now let's add the correct badges - yq -ei 'del(.badges[] | select(.name == "*Release*"))' ${readme_yaml} - yq -ei '.badges += [ - { - "name": "Latest Release", - "image": "https://img.shields.io/github/release/" + env(GITHUB_REPO) + ".svg?style=for-the-badge", - "url": "https://github.com/" + env(GITHUB_REPO) + "/releases/latest" - } - ]' ${readme_yaml} - - yq -ei 'del(.badges[] | select(.name == "*Updated*"))' ${readme_yaml} - yq -ei 'del(.badges[] | select(.name == "*Commit*"))' ${readme_yaml} - yq -ei '.badges += [ - { - "name": "Last Updated", - "image": "https://img.shields.io/github/last-commit/" + env(GITHUB_REPO) + ".svg?style=for-the-badge", - "url": "https://github.com/" + env(GITHUB_REPO) + "/commits" - } - ]' ${readme_yaml} - - if [ -f ".github/workflows/test.yml" ]; then - yq -ei 'del(.badges[] | select(.name == "*Test*"))' ${readme_yaml} - yq -ei '.badges += [ - { - "name": "Tests", - "image": "https://img.shields.io/github/actions/workflow/status/" + env(GITHUB_REPO) + "/test.yml?style=for-the-badge", - "url": "https://github.com/" + (env(GITHUB_REPO) | tostring) + "/actions/workflows/test.yml" - } - ]' ${readme_yaml} - fi - - - if [ -f ".github/workflows/lambda.yml" ]; then - yq -ei 'del(.badges[] | select(.name == "*Test*"))' ${readme_yaml} - yq -ei '.badges += [ - { - "name": "Tests", - "image": "https://img.shields.io/github/actions/workflow/status/" + env(GITHUB_REPO) + "/lambda.yml?style=for-the-badge", - "url": "https://github.com/" + env(GITHUB_REPO) + "/actions/workflows/lambda.yml" - } - ]' ${readme_yaml} - fi - - # This should always be the last badge we append, so it appears on the right. - yq -ei 'del(.badges[] | select(.name == "*Slack*"))' ${readme_yaml} - yq -ei '.badges += [ - { - "name": "Slack Community", - "image": "https://slack.cloudposse.com/for-the-badge.svg", - "url": "https://slack.cloudposse.com" - } - ]' ${readme_yaml} - - # Format the YAML for humans - yamlfix -c ${MIGRATE_PATH}/yamlfix.yml $readme_yaml -} diff --git a/migrate/lib/common.sh b/migrate/lib/common.sh index 3fc11d9d..b4b08004 100644 --- a/migrate/lib/common.sh +++ b/migrate/lib/common.sh @@ -3,14 +3,47 @@ function title() { } function error() { - printf "“❌ \e[31mError: %s\e[0m\n" "$*" + printf "“❌ \e[31mError: %s\e[0m\n" "$*" >&2 exit 1 } function info() { - printf "✅︎ %s\n" "$*" + printf "✅︎ %s\n" "$*" >&2 } +function gh() { + while true; do + # Check the GitHub API rate limit + rate_limit=$(command gh api rate_limit | jq '.resources.core.remaining') + + # Print the current rate limit + info "GitHub API rate limit: $rate_limit remaining" + + # If the rate limit is sufficient, break the loop + if (( rate_limit > 10 )); then + break + fi + + # Sleep for 60 seconds before checking the rate limit again + info "Rate limit too low, sleeping for 60 seconds..." + sleep 60 + done + + # Call the gh command with the provided arguments + command gh "$@" + exit_code=$? + # Generate a random number between 500 and 3000 (representing milliseconds) + random_milliseconds=$(( RANDOM % 2500 + 500 )) + + # Convert milliseconds to seconds + random_seconds=$(echo "scale=3; $random_milliseconds / 1000" | bc) + + # Sleep for the random amount of time + sleep $random_seconds + return $exit_code +} + + function install() { local source=${1} local destination=${2:-$source} @@ -66,11 +99,11 @@ function create_labels() { IFS=',' read -ra required_labels <<< "$LABELS" - local existing_labels=$(gh label list) + local existing_labels=$(gh label list --json name --jq '.[].name') for label in "${required_labels[@]}"; do if ! echo "$existing_labels" | grep -q "$label"; then - gh label create $label -c '#b60205' + gh label create "$label" -c '#b60205' info "Created label [$label]" fi done diff --git a/migrate/lib/github-settings.sh b/migrate/lib/github-settings.sh index 8184e2a5..7c912da6 100644 --- a/migrate/lib/github-settings.sh +++ b/migrate/lib/github-settings.sh @@ -16,13 +16,25 @@ function install_github_settings() { info "Creating $settings" echo "_extends: .github" > $settings fi + # Fetch the current name and description of the repo and update the settings file + local repo_description=$(gh repo view --json description --jq '.description') + local repo_homepage=$(gh repo view --json homepageUrl --jq '.homepageUrl') + local repo_topics=$(gh api repos/{owner}/{repo}/topics --jq '.names | join(", ")') + + yq -ei ".repository.name = \"$XARGS_REPO_NAME\"" $settings + yq -ei ".repository.description = \"$repo_description\"" $settings + if [ -z "$repo_homepage" ]; then + yq -ei ".repository.homepage = \"https://cloudposse.com/accelerate\"" $settings + else + yq -ei ".repository.homepage = \"$repo_homepage\"" $settings + fi + + yq -ei ".repository.topics = \"$repo_topics\"" $settings # finally, let's sort the file so _extends is at the top. yq -ei 'sort_keys(.)' $settings - - # Format the YAML for humans - yamlfix -c ${MIGRATE_PATH}/yamlfix.yml $settings - + sed -i '' '/# Upstream changes/d' $settings + yq -ei '(._extends | key) head_comment="Upstream changes from _extends are only recognized when modifications are made to this file in the default branch."' $settings + git add $settings - } diff --git a/migrate/lib/github.sh b/migrate/lib/github.sh new file mode 100644 index 00000000..728cbd4a --- /dev/null +++ b/migrate/lib/github.sh @@ -0,0 +1,5 @@ + +function delete_branch_protection() { + local default_branch=$(git remote show origin | grep 'HEAD branch' | cut -d' ' -f5) + gh api -X DELETE /repos/${XARGS_REPO_OWNER}/${XARGS_REPO_NAME}/branches/${default_branch}/protection +} \ No newline at end of file diff --git a/migrate/lib/mergify.sh b/migrate/lib/mergify.sh index 7946e6fa..eeafd3ca 100644 --- a/migrate/lib/mergify.sh +++ b/migrate/lib/mergify.sh @@ -4,6 +4,19 @@ function install_mergify() { local config=".github/mergify.yml" mkdir -p $(dirname $config) + + case "${REPO_TYPE}" in + "terraform-provider") + rm -f $config + ;; + "terraform-module") + rm -f $config + ;; + "github-action") + rm -f $config + ;; + esac + if [ -f $config ]; then info "Mergify config already installed" # Ensure it's always extending from the .github repo diff --git a/migrate/lib/readme.py b/migrate/lib/readme.py new file mode 100755 index 00000000..9c4c7341 --- /dev/null +++ b/migrate/lib/readme.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python3 + +# This implementation uses ruamel.yaml, a python library that can handle whitespace and comments. +# +# The first implementation attempted to use `yq` to parse the YAML file and update the badges section. +# Unfortunately, yq loses whitespace, and rewrites any multi-line strings and quoted strings. +# This caused the README.yaml to be reformatted and lose its original structure, which is not acceptable. +# It turns out that many YAML processors (especially based on Go) do not properly handle whitespace, +# comments, and multi-line strings in YAML. +# - https://github.com/mikefarah/yq/discussions/1584 +# - https://github.com/go-yaml/yaml/issues/827 +# + +import sys +import os +from ruamel.yaml import YAML + +def add_newlines_before_comments(data): + prev_item = None + for item in data.items(): + key_node = item[0] + # Check if the current node has a comment + if hasattr(key_node, 'comment') and key_node.comment: + comment = key_node.comment[0] + if comment and prev_item and not (hasattr(prev_item, 'comment') and prev_item.comment): + # Add a newline before the current comment block only if the previous item does not have a comment + prev_item.comment[2] = ['\n'] + prev_item = key_node + + +def migrate_readme(readme_yaml="README.yaml"): + yaml = YAML() + yaml.preserve_quotes = True + yaml.indent(mapping=2, sequence=4, offset=2) + yaml.width = 4096 # Set to a large number to avoid line wrapping + data = None + + documents = [] + + # Load the YAML file with potentially multiple documents + try: + with open(readme_yaml, 'r') as file: + documents = list(yaml.load_all(file)) + except FileNotFoundError: + print(f"{readme_yaml} file not found.") + return + + for data in documents: + + github_repo = data.get('github_repo', None) + if not github_repo or github_repo == "None": + if 'GITHUB_REPO' in os.environ: + data['github_repo'] = os.environ['GITHUB_REPO'] + github_repo = data['github_repo'] + else: + print(f"github_repo is not set in the {readme_yaml} file.") + pass + + if 'badges' in data and isinstance(data['badges'], list): + # Names of badges to be removed (substrings) + badges_to_remove = ['Codefresh', 'Build Status', 'Latest Release', 'Last Updated', 'Commit', 'GitHub Action Build Status', 'Discourse', 'Forum', 'Slack'] + + # Remove unwanted badges + data['badges'] = [badge for badge in data['badges'] if not any(removal_str in badge['name'].strip() for removal_str in badges_to_remove)] + else: + data['badges'] = [] + + # Add new badges + new_badges = [ + {"name": "Latest Release", "image": f"https://img.shields.io/github/release/{github_repo}.svg?style=for-the-badge", "url": f"https://github.com/{github_repo}/releases/latest"}, + {"name": "Last Updated", "image": f"https://img.shields.io/github/last-commit/{github_repo}.svg?style=for-the-badge", "url": f"https://github.com/{github_repo}/commits"}, + {"name": "Slack Community", "image": "https://slack.cloudposse.com/for-the-badge.svg", "url": "https://slack.cloudposse.com"} + ] + + # Add badges for specific workflow files if they exist + if os.path.isfile(".github/workflows/test.yml"): + new_badges.append({"name": "Tests", "image": f"https://img.shields.io/github/actions/workflow/status/{github_repo}/test.yml?style=for-the-badge", "url": f"https://github.com/{github_repo}/actions/workflows/test.yml"}) + + if os.path.isfile(".github/workflows/lambda.yml"): + new_badges.append({"name": "Tests", "image": f"https://img.shields.io/github/actions/workflow/status/{github_repo}/lambda.yml?style=for-the-badge", "url": f"https://github.com/{github_repo}/actions/workflows/lambda.yml"}) + + data['badges'].extend(new_badges) + + # Ruamel accidentally deletes this comment sometimes when updating the badges + data.yaml_set_comment_before_after_key('related', before='\nList any related terraform modules that this module may be used with or that this module depends on.') + + # Set 'contributors' section to an empty array, as we handle this now with an image + data['contributors'] = [] + + add_newlines_before_comments(data) + + # Write back the updated YAML with multiple documents + with open(readme_yaml, 'w') as file: + yaml.dump_all(documents, file) + +if __name__ == "__main__": + migrate_readme(sys.argv[1]) diff --git a/migrate/lib/readme.sh b/migrate/lib/readme.sh index 827056d8..35f32f6c 100644 --- a/migrate/lib/readme.sh +++ b/migrate/lib/readme.sh @@ -1,5 +1,18 @@ #!/bin/bash +function migrate_readme() { + + readme_yaml="${1:-README.yaml}" + + if [ ! -f "${readme_yaml}" ]; then + error "${readme_yaml} file not found." + fi + # This is used in the event `github_repo` is not properly set in the `README.yaml` + export GITHUB_REPO="${XARGS_REPO_OWNER}/${XARGS_REPO_NAME}" + ${MIGRATE_PATH}/lib/readme.py ${readme_yaml} +} + + function rebuild_readme() { if [ ! -f README.yaml ]; then info "README.yaml file not found, skipping..." @@ -10,3 +23,59 @@ function rebuild_readme() { git add README.md } + +function generate_description() { + local description=$(cat README.yaml *.tf | \ + mods --no-cache --quiet --word-wrap=2048 --raw -f \ + 'Provide a clear 1-3 sentence description in a spartan conversational tone, that describes this terraform module suitable \ + for inclusion in the README.md of the module. Respond with GitHub flavored markdown and use links where appropriate. The target \ + audience is developers with terraform knowledge. Do not link the Terraform term. Do not link to the module you are describing. \ + Use code ticks for things like shell commands, terraform resources, modules or kubernetes resource definitions. Avoid too many adjectives \ + or hyperbole. Focus on what it is and does.') + +} + +function generate_introduction() { + local description=$(cat README.yaml *.tf | \ + mods --no-cache --quiet --word-wrap=2048 --raw -f \ + 'Act as an expert technical documentation writer with experience writing technical documentation for Open Source projects. \ + Write a thorough explanation for a chapter of a REAMDE that explains what this module does in a spartan conversational tone written by an experienced DevOps engineer.\ + Focus on what it is and does. Use concrete terms of what it does, not aspirations and endeavors. \ + It can be as long as necessary. \ + Add a section called "Key Features" which very succinctly highlights to top features of the module, but do not include the examples or features of the examples that do not directly relate to the module. \ + This feature list should be a bulleted list. + This repo is identified by the "github_repo" key in the README.yaml file. \ + Respond with GitHub flavored markdown and use links where appropriate. \ + The target audience is developers with terraform knowledge. \ + If discussing Cloud Posse, link to https://cloudposse.com, but only the first time per paragraph. Use "Cloud Posse" instead of "CloudPosse" \ + Use code ticks for things like shell commands, terraform resources, modules or kubernetes resource definitions. \ + Link to any modules referenced, with exception of the current module. \ + For AWS services, link to the most relevant page in the AWS documentation. \ + For each AWS service used by the module, explain succinctly what it is and the benefit of why it is used. \ + For example, if you are using an S3 bucket, link to the S3 documentation.\ + This explanation will be present within the repository itself, so do not directly suggest to visit module or repository itself.\ + We discuss related modules elsewhere, so only bring up the most relevant ones here, if necessary. + Any modules discussed should also be linked to their documentation. \ + Any terraform resources referenced should be linked to their documentation. \ + Combine many one sentence parargraphs into a single paragraph. \ + Do not use fancy words like "repertoire" or try to sound cute. \ + Do not say things like as stated in the documentation or as stated in the README. \ + Do not use the "related" or "references" section from the README.yaml as part of the description. \ + Do not say "This repository" or "This project". \ + Do not state the obvious. \ + DO not state things such as "This module is a Terraform module" or that they need to have an AWS account or login credentials or the benefits in general of using modules.\ + Do not say things like "Go back to the index" or "Read the next chapter" as this is not a book. \ + Do not repeat the name of the current module multiple times in the explanation. + Do not reuse the same phrases repeatedly like "key feature" over and over again. \ + Do not use too many adjectives and avoid hyperbole. \ + Do not add a conclusion or summary.\ + Do not break it into additional chapters, unless asked. \ + Do not add a title. \ + Do not link the Terraform term. \ + Do not link to the module you are describing. \ + Do not say anything like "this module presupposes general background knowledge" \ + Do not discuss cost of provisioning the resources. \ + Do not link to any other chapters with anchors. \ + Do not include example usage, or further information as the focus needs to be on the module itself. \ + ') +} diff --git a/migrate/migrations/20240302/test-badges.yaml b/migrate/migrations/20240302/test-badges.yaml index f3fcf49c..a1230b6f 100644 --- a/migrate/migrations/20240302/test-badges.yaml +++ b/migrate/migrations/20240302/test-badges.yaml @@ -1,3 +1,4 @@ +github_repo: 'XXXXXXX' badges: - name: "Latest Release" image: "https://img.shields.io/github/release/cloudposse/terraform-aws-msk-apache-kafka-cluster.svg" @@ -15,6 +16,10 @@ badges: image: https://slack.cloudposse.com/badge.svg url: https://slack.cloudposse.com +- name: "Unique Badge" + image: https://foobar.com/badge.svg + url: https://foobar.com + - name: "Codefresh Build Status" image: "https://g.codefresh.io/api/badges/pipeline/cloudposse/terraform-modules%2Fterraform-aws-ecs-web-app?type=cf-1" url: "https://g.codefresh.io/public/accounts/cloudposse/pipelines/5dbb22a15c2e97b3b73ab484" diff --git a/migrate/migrations/20240304/README.md b/migrate/migrations/20240304/README.md index 2258b3ef..5225331d 100644 --- a/migrate/migrations/20240304/README.md +++ b/migrate/migrations/20240304/README.md @@ -1,7 +1,7 @@ ## what - Reran `make readme` to rebuild `README.md` from `README.yaml` - Migrate to square badges -- Add scaffolding for Settings, Renovate, Dependabot, and Mergify +- Add scaffolding for repo settings and Mergify ## why - Upstream template changed in the `.github` repo diff --git a/migrate/migrations/20240304/repos-00 b/migrate/migrations/20240304/repos-00 new file mode 100644 index 00000000..26ef0cf6 --- /dev/null +++ b/migrate/migrations/20240304/repos-00 @@ -0,0 +1,16 @@ +cloudposse/terraform-aws-vpc +cloudposse/terraform-aws-elastic-beanstalk-application +cloudposse/terraform-aws-elastic-beanstalk-environment +cloudposse/terraform-aws-ec2-bastion-server +cloudposse/terraform-aws-rds-cluster +cloudposse/terraform-aws-cicd +cloudposse/terraform-aws-route53-cluster-zone +cloudposse/terraform-aws-efs +cloudposse/terraform-aws-route53-cluster-hostname +cloudposse/terraform-aws-elasticache-memcached +cloudposse/terraform-aws-route53-alias +cloudposse/terraform-null-label +cloudposse/terraform-aws-iam-assumed-roles +cloudposse/terraform-null-ansible +cloudposse/terraform-aws-ec2-ami-snapshot +cloudposse/terraform-aws-ec2-ami-backup diff --git a/migrate/migrations/20240304/repos-01 b/migrate/migrations/20240304/repos-01 new file mode 100644 index 00000000..3373bb2d --- /dev/null +++ b/migrate/migrations/20240304/repos-01 @@ -0,0 +1,16 @@ +cloudposse/terraform-aws-ec2-instance +cloudposse/terraform-aws-efs-backup +cloudposse/terraform-aws-elasticache-redis +cloudposse/terraform-aws-cloudtrail +cloudposse/terraform-aws-codebuild +cloudposse/terraform-aws-dynamic-subnets +cloudposse/terraform-aws-ec2-admin-server +cloudposse/terraform-aws-ecr +cloudposse/terraform-aws-rds +cloudposse/terraform-aws-key-pair +cloudposse/terraform-datadog-platform +cloudposse/terraform-aws-cloudfront-s3-cdn +cloudposse/terraform-aws-s3-log-storage +cloudposse/terraform-aws-s3-website +cloudposse/terraform-aws-cloudfront-cdn +cloudposse/terraform-aws-acm-request-certificate diff --git a/migrate/migrations/20240304/repos-02 b/migrate/migrations/20240304/repos-02 new file mode 100644 index 00000000..0e348c4a --- /dev/null +++ b/migrate/migrations/20240304/repos-02 @@ -0,0 +1,16 @@ +cloudposse/terraform-aws-iam-system-user +cloudposse/terraform-aws-datadog-integration +cloudposse/terraform-aws-named-subnets +cloudposse/terraform-aws-cloudwatch-flow-logs +cloudposse/terraform-aws-vpc-peering +cloudposse/terraform-aws-multi-az-subnets +cloudposse/terraform-aws-cloudwatch-logs +cloudposse/terraform-aws-dynamodb +cloudposse/terraform-aws-organization-access-role +cloudposse/terraform-aws-organization-access-group +cloudposse/terraform-aws-tfstate-backend +cloudposse/terraform-aws-dynamodb-autoscaler +cloudposse/terraform-aws-cloudtrail-s3-bucket +cloudposse/terraform-aws-kms-key +cloudposse/terraform-tls-ssh-key-pair +cloudposse/terraform-aws-components diff --git a/migrate/migrations/20240304/repos-03 b/migrate/migrations/20240304/repos-03 new file mode 100644 index 00000000..420e53dd --- /dev/null +++ b/migrate/migrations/20240304/repos-03 @@ -0,0 +1,16 @@ +cloudposse/terraform-aws-iam-s3-user +cloudposse/terraform-terraform-label +cloudposse/terraform-aws-ssm-parameter-store +cloudposse/terraform-aws-ecs-events +cloudposse/terraform-aws-ec2-instance-group +cloudposse/terraform-aws-rds-cloudwatch-sns-alarms +cloudposse/terraform-aws-efs-cloudwatch-sns-alarms +cloudposse/terraform-aws-elasticache-cloudwatch-sns-alarms +cloudposse/terraform-aws-ecs-container-definition +cloudposse/terraform-aws-ecs-alb-service-task +cloudposse/terraform-aws-lb-s3-bucket +cloudposse/terraform-aws-ecs-codepipeline +cloudposse/terraform-aws-alb +cloudposse/terraform-aws-alb-ingress +cloudposse/terraform-aws-sqs-cloudwatch-sns-alarms +cloudposse/terraform-aws-lambda-cloudwatch-sns-alarms diff --git a/migrate/migrations/20240304/repos-04 b/migrate/migrations/20240304/repos-04 new file mode 100644 index 00000000..bbc132c8 --- /dev/null +++ b/migrate/migrations/20240304/repos-04 @@ -0,0 +1,16 @@ +cloudposse/terraform-aws-ssm-iam-role +cloudposse/terraform-aws-ecs-spot-fleet +cloudposse/terraform-aws-ecs-web-app +cloudposse/terraform-aws-ssm-parameter-store-policy-documents +cloudposse/terraform-aws-cloudtrail-cloudwatch-alarms +cloudposse/terraform-aws-ecs-cloudwatch-sns-alarms +cloudposse/terraform-aws-sns-lambda-notify-slack +cloudposse/terraform-aws-alb-target-group-cloudwatch-sns-alarms +cloudposse/terraform-aws-ses-lambda-forwarder +cloudposse/terraform-aws-ecs-cloudwatch-autoscaling +cloudposse/terraform-aws-eks-cluster +cloudposse/terraform-aws-eks-workers +cloudposse/terraform-aws-ec2-autoscale-group +cloudposse/terraform-aws-ecs-launch-template +cloudposse/terraform-aws-elasticsearch +cloudposse/terraform-aws-iam-user diff --git a/migrate/migrations/20240304/repos-05 b/migrate/migrations/20240304/repos-05 new file mode 100644 index 00000000..10d1e9ef --- /dev/null +++ b/migrate/migrations/20240304/repos-05 @@ -0,0 +1,16 @@ +cloudposse/terraform-null-smtp-mail +cloudposse/terraform-aws-iam-account-settings +cloudposse/terraform-github-repository-webhooks +cloudposse/terraform-aws-lambda-elasticsearch-cleanup +cloudposse/terraform-external-module-artifact +cloudposse/terraform-aws-ssm-tls-ssh-key-pair +cloudposse/terraform-aws-rds-replica +cloudposse/terraform-aws-rds-cluster-instance-group +cloudposse/terraform-aws-vpc-peering-multi-account +cloudposse/terraform-aws-s3-bucket +cloudposse/terraform-aws-mq-broker +cloudposse/terraform-aws-vpn-connection +cloudposse/terraform-aws-iam-chamber-s3-role +cloudposse/terraform-aws-iam-role +cloudposse/terraform-aws-documentdb-cluster +cloudposse/terraform-aws-cloudformation-stack-set diff --git a/migrate/migrations/20240304/repos-06 b/migrate/migrations/20240304/repos-06 new file mode 100644 index 00000000..870a55a8 --- /dev/null +++ b/migrate/migrations/20240304/repos-06 @@ -0,0 +1,16 @@ +cloudposse/terraform-aws-emr-cluster +cloudposse/terraform-aws-vpc-flow-logs-s3-bucket +cloudposse/terraform-aws-backup +cloudposse/terraform-aws-cloudformation-stack +cloudposse/terraform-aws-ssm-parameter-chamber-reader +cloudposse/terraform-aws-eks-fargate-profile +cloudposse/terraform-aws-eks-node-group +cloudposse/terraform-aws-spotinst-mrscaler +cloudposse/terraform-aws-nlb +cloudposse/terraform-aws-eks-iam-role +cloudposse/terraform-aws-ses +cloudposse/terraform-example-module +cloudposse/terraform-aws-sns-topic +cloudposse/terraform-aws-sns-cloudwatch-sns-alarms +cloudposse/terraform-aws-transit-gateway +cloudposse/terraform-aws-cloudwatch-events diff --git a/migrate/migrations/20240304/repos-07 b/migrate/migrations/20240304/repos-07 new file mode 100644 index 00000000..46ac86ff --- /dev/null +++ b/migrate/migrations/20240304/repos-07 @@ -0,0 +1,16 @@ +cloudposse/terraform-opsgenie-incident-management +cloudposse/terraform-aws-msk-apache-kafka-cluster +cloudposse/terraform-aws-utils +cloudposse/terraform-kubernetes-tfc-cloud-agent +cloudposse/terraform-spacelift-cloud-infrastructure-automation +cloudposse/terraform-aws-security-hub +cloudposse/terraform-aws-service-control-policies +cloudposse/terraform-aws-guardduty +cloudposse/terraform-yaml-config +cloudposse/terraform-aws-config-storage +cloudposse/terraform-aws-config +cloudposse/terraform-aws-inspector +cloudposse/terraform-aws-eks-spotinst-ocean-nodepool +cloudposse/terraform-yaml-stack-config +cloudposse/terraform-provider-utils +cloudposse/terraform-aws-security-group diff --git a/migrate/migrations/20240304/repos-08 b/migrate/migrations/20240304/repos-08 new file mode 100644 index 00000000..21831ce8 --- /dev/null +++ b/migrate/migrations/20240304/repos-08 @@ -0,0 +1,16 @@ +cloudposse/terraform-aws-sso +cloudposse/terraform-aws-firewall-manager +cloudposse/terraform-aws-code-deploy +cloudposse/terraform-aws-rds-db-proxy +cloudposse/terraform-cloudflare-zone +cloudposse/terraform-cloudflare-waf-rulesets +cloudposse/terraform-aws-waf +cloudposse/terraform-aws-redshift-cluster +cloudposse/terraform-aws-health-events +cloudposse/terraform-aws-macie +cloudposse/terraform-aws-global-accelerator +cloudposse/terraform-aws-ssm-patch-manager +cloudposse/terraform-provider-awsutils +cloudposse/terraform-aws-helm-release +cloudposse/terraform-aws-iam-policy +cloudposse/terraform-aws-transfer-sftp diff --git a/migrate/migrations/20240304/repos-09 b/migrate/migrations/20240304/repos-09 new file mode 100644 index 00000000..b859f023 --- /dev/null +++ b/migrate/migrations/20240304/repos-09 @@ -0,0 +1,16 @@ +cloudposse/terraform-aws-ssm-tls-self-signed-cert +cloudposse/terraform-aws-datadog-lambda-forwarder +cloudposse/terraform-aws-ec2-client-vpn +cloudposse/terraform-aws-api-gateway +cloudposse/terraform-aws-mwaa +cloudposse/terraform-aws-lambda-function +cloudposse/terraform-aws-service-quotas +cloudposse/terraform-aws-budgets +cloudposse/terraform-aws-ecr-public +cloudposse/terraform-aws-amplify-app +#cloudposse/terraform-provider-atmos +cloudposse/terraform-aws-glue +cloudposse/terraform-aws-github-action-token-rotator +cloudposse/terraform-aws-athena +cloudposse/terraform-aws-lakeformation +cloudposse/terraform-aws-kinesis-stream diff --git a/migrate/migrations/20240304/repos-10 b/migrate/migrations/20240304/repos-10 new file mode 100644 index 00000000..b2b2ad2f --- /dev/null +++ b/migrate/migrations/20240304/repos-10 @@ -0,0 +1,8 @@ +cloudposse/terraform-aws-dms +cloudposse/terraform-aws-ecs-cluster +cloudposse/terraform-aws-network-firewall +cloudposse/terraform-aws-route53-resolver-dns-firewall +cloudposse/terraform-module-test +cloudposse/terraform-aws-step-functions +cloudposse/terraform-aws-kv-store +cloudposse/terraform-aws-refarch-utils diff --git a/migrate/migrations/20240304/script.sh b/migrate/migrations/20240304/script.sh index ba782309..37a459fe 100644 --- a/migrate/migrations/20240304/script.sh +++ b/migrate/migrations/20240304/script.sh @@ -1,7 +1,12 @@ title "Update Scaffolding" -migrate_badges +migrate_readme rebuild_readme install_mergify -#auto_merge +# We've implemented repository rulesets to replace this functionality +# We don't care if it errors right now, as it might have already run. +(delete_branch_protection >/dev/null 2>&1) || true + +# Merge the PR +auto_merge diff --git a/migrate/migrations/20240314/README.md b/migrate/migrations/20240314/README.md new file mode 100644 index 00000000..2597da4b --- /dev/null +++ b/migrate/migrations/20240314/README.md @@ -0,0 +1,5 @@ +## what +- Install a repository config (`.github/settings.yaml`) + +## why +- Programmatically manage GitHub repo settings diff --git a/migrate/migrations/20240314/repos-00 b/migrate/migrations/20240314/repos-00 new file mode 100644 index 00000000..26ef0cf6 --- /dev/null +++ b/migrate/migrations/20240314/repos-00 @@ -0,0 +1,16 @@ +cloudposse/terraform-aws-vpc +cloudposse/terraform-aws-elastic-beanstalk-application +cloudposse/terraform-aws-elastic-beanstalk-environment +cloudposse/terraform-aws-ec2-bastion-server +cloudposse/terraform-aws-rds-cluster +cloudposse/terraform-aws-cicd +cloudposse/terraform-aws-route53-cluster-zone +cloudposse/terraform-aws-efs +cloudposse/terraform-aws-route53-cluster-hostname +cloudposse/terraform-aws-elasticache-memcached +cloudposse/terraform-aws-route53-alias +cloudposse/terraform-null-label +cloudposse/terraform-aws-iam-assumed-roles +cloudposse/terraform-null-ansible +cloudposse/terraform-aws-ec2-ami-snapshot +cloudposse/terraform-aws-ec2-ami-backup diff --git a/migrate/migrations/20240314/repos-01 b/migrate/migrations/20240314/repos-01 new file mode 100644 index 00000000..3373bb2d --- /dev/null +++ b/migrate/migrations/20240314/repos-01 @@ -0,0 +1,16 @@ +cloudposse/terraform-aws-ec2-instance +cloudposse/terraform-aws-efs-backup +cloudposse/terraform-aws-elasticache-redis +cloudposse/terraform-aws-cloudtrail +cloudposse/terraform-aws-codebuild +cloudposse/terraform-aws-dynamic-subnets +cloudposse/terraform-aws-ec2-admin-server +cloudposse/terraform-aws-ecr +cloudposse/terraform-aws-rds +cloudposse/terraform-aws-key-pair +cloudposse/terraform-datadog-platform +cloudposse/terraform-aws-cloudfront-s3-cdn +cloudposse/terraform-aws-s3-log-storage +cloudposse/terraform-aws-s3-website +cloudposse/terraform-aws-cloudfront-cdn +cloudposse/terraform-aws-acm-request-certificate diff --git a/migrate/migrations/20240314/repos-02 b/migrate/migrations/20240314/repos-02 new file mode 100644 index 00000000..0e348c4a --- /dev/null +++ b/migrate/migrations/20240314/repos-02 @@ -0,0 +1,16 @@ +cloudposse/terraform-aws-iam-system-user +cloudposse/terraform-aws-datadog-integration +cloudposse/terraform-aws-named-subnets +cloudposse/terraform-aws-cloudwatch-flow-logs +cloudposse/terraform-aws-vpc-peering +cloudposse/terraform-aws-multi-az-subnets +cloudposse/terraform-aws-cloudwatch-logs +cloudposse/terraform-aws-dynamodb +cloudposse/terraform-aws-organization-access-role +cloudposse/terraform-aws-organization-access-group +cloudposse/terraform-aws-tfstate-backend +cloudposse/terraform-aws-dynamodb-autoscaler +cloudposse/terraform-aws-cloudtrail-s3-bucket +cloudposse/terraform-aws-kms-key +cloudposse/terraform-tls-ssh-key-pair +cloudposse/terraform-aws-components diff --git a/migrate/migrations/20240314/repos-03 b/migrate/migrations/20240314/repos-03 new file mode 100644 index 00000000..420e53dd --- /dev/null +++ b/migrate/migrations/20240314/repos-03 @@ -0,0 +1,16 @@ +cloudposse/terraform-aws-iam-s3-user +cloudposse/terraform-terraform-label +cloudposse/terraform-aws-ssm-parameter-store +cloudposse/terraform-aws-ecs-events +cloudposse/terraform-aws-ec2-instance-group +cloudposse/terraform-aws-rds-cloudwatch-sns-alarms +cloudposse/terraform-aws-efs-cloudwatch-sns-alarms +cloudposse/terraform-aws-elasticache-cloudwatch-sns-alarms +cloudposse/terraform-aws-ecs-container-definition +cloudposse/terraform-aws-ecs-alb-service-task +cloudposse/terraform-aws-lb-s3-bucket +cloudposse/terraform-aws-ecs-codepipeline +cloudposse/terraform-aws-alb +cloudposse/terraform-aws-alb-ingress +cloudposse/terraform-aws-sqs-cloudwatch-sns-alarms +cloudposse/terraform-aws-lambda-cloudwatch-sns-alarms diff --git a/migrate/migrations/20240314/repos-04 b/migrate/migrations/20240314/repos-04 new file mode 100644 index 00000000..bbc132c8 --- /dev/null +++ b/migrate/migrations/20240314/repos-04 @@ -0,0 +1,16 @@ +cloudposse/terraform-aws-ssm-iam-role +cloudposse/terraform-aws-ecs-spot-fleet +cloudposse/terraform-aws-ecs-web-app +cloudposse/terraform-aws-ssm-parameter-store-policy-documents +cloudposse/terraform-aws-cloudtrail-cloudwatch-alarms +cloudposse/terraform-aws-ecs-cloudwatch-sns-alarms +cloudposse/terraform-aws-sns-lambda-notify-slack +cloudposse/terraform-aws-alb-target-group-cloudwatch-sns-alarms +cloudposse/terraform-aws-ses-lambda-forwarder +cloudposse/terraform-aws-ecs-cloudwatch-autoscaling +cloudposse/terraform-aws-eks-cluster +cloudposse/terraform-aws-eks-workers +cloudposse/terraform-aws-ec2-autoscale-group +cloudposse/terraform-aws-ecs-launch-template +cloudposse/terraform-aws-elasticsearch +cloudposse/terraform-aws-iam-user diff --git a/migrate/migrations/20240314/repos-05 b/migrate/migrations/20240314/repos-05 new file mode 100644 index 00000000..10d1e9ef --- /dev/null +++ b/migrate/migrations/20240314/repos-05 @@ -0,0 +1,16 @@ +cloudposse/terraform-null-smtp-mail +cloudposse/terraform-aws-iam-account-settings +cloudposse/terraform-github-repository-webhooks +cloudposse/terraform-aws-lambda-elasticsearch-cleanup +cloudposse/terraform-external-module-artifact +cloudposse/terraform-aws-ssm-tls-ssh-key-pair +cloudposse/terraform-aws-rds-replica +cloudposse/terraform-aws-rds-cluster-instance-group +cloudposse/terraform-aws-vpc-peering-multi-account +cloudposse/terraform-aws-s3-bucket +cloudposse/terraform-aws-mq-broker +cloudposse/terraform-aws-vpn-connection +cloudposse/terraform-aws-iam-chamber-s3-role +cloudposse/terraform-aws-iam-role +cloudposse/terraform-aws-documentdb-cluster +cloudposse/terraform-aws-cloudformation-stack-set diff --git a/migrate/migrations/20240314/repos-06 b/migrate/migrations/20240314/repos-06 new file mode 100644 index 00000000..870a55a8 --- /dev/null +++ b/migrate/migrations/20240314/repos-06 @@ -0,0 +1,16 @@ +cloudposse/terraform-aws-emr-cluster +cloudposse/terraform-aws-vpc-flow-logs-s3-bucket +cloudposse/terraform-aws-backup +cloudposse/terraform-aws-cloudformation-stack +cloudposse/terraform-aws-ssm-parameter-chamber-reader +cloudposse/terraform-aws-eks-fargate-profile +cloudposse/terraform-aws-eks-node-group +cloudposse/terraform-aws-spotinst-mrscaler +cloudposse/terraform-aws-nlb +cloudposse/terraform-aws-eks-iam-role +cloudposse/terraform-aws-ses +cloudposse/terraform-example-module +cloudposse/terraform-aws-sns-topic +cloudposse/terraform-aws-sns-cloudwatch-sns-alarms +cloudposse/terraform-aws-transit-gateway +cloudposse/terraform-aws-cloudwatch-events diff --git a/migrate/migrations/20240314/repos-07 b/migrate/migrations/20240314/repos-07 new file mode 100644 index 00000000..46ac86ff --- /dev/null +++ b/migrate/migrations/20240314/repos-07 @@ -0,0 +1,16 @@ +cloudposse/terraform-opsgenie-incident-management +cloudposse/terraform-aws-msk-apache-kafka-cluster +cloudposse/terraform-aws-utils +cloudposse/terraform-kubernetes-tfc-cloud-agent +cloudposse/terraform-spacelift-cloud-infrastructure-automation +cloudposse/terraform-aws-security-hub +cloudposse/terraform-aws-service-control-policies +cloudposse/terraform-aws-guardduty +cloudposse/terraform-yaml-config +cloudposse/terraform-aws-config-storage +cloudposse/terraform-aws-config +cloudposse/terraform-aws-inspector +cloudposse/terraform-aws-eks-spotinst-ocean-nodepool +cloudposse/terraform-yaml-stack-config +cloudposse/terraform-provider-utils +cloudposse/terraform-aws-security-group diff --git a/migrate/migrations/20240314/repos-08 b/migrate/migrations/20240314/repos-08 new file mode 100644 index 00000000..21831ce8 --- /dev/null +++ b/migrate/migrations/20240314/repos-08 @@ -0,0 +1,16 @@ +cloudposse/terraform-aws-sso +cloudposse/terraform-aws-firewall-manager +cloudposse/terraform-aws-code-deploy +cloudposse/terraform-aws-rds-db-proxy +cloudposse/terraform-cloudflare-zone +cloudposse/terraform-cloudflare-waf-rulesets +cloudposse/terraform-aws-waf +cloudposse/terraform-aws-redshift-cluster +cloudposse/terraform-aws-health-events +cloudposse/terraform-aws-macie +cloudposse/terraform-aws-global-accelerator +cloudposse/terraform-aws-ssm-patch-manager +cloudposse/terraform-provider-awsutils +cloudposse/terraform-aws-helm-release +cloudposse/terraform-aws-iam-policy +cloudposse/terraform-aws-transfer-sftp diff --git a/migrate/migrations/20240314/repos-09 b/migrate/migrations/20240314/repos-09 new file mode 100644 index 00000000..b859f023 --- /dev/null +++ b/migrate/migrations/20240314/repos-09 @@ -0,0 +1,16 @@ +cloudposse/terraform-aws-ssm-tls-self-signed-cert +cloudposse/terraform-aws-datadog-lambda-forwarder +cloudposse/terraform-aws-ec2-client-vpn +cloudposse/terraform-aws-api-gateway +cloudposse/terraform-aws-mwaa +cloudposse/terraform-aws-lambda-function +cloudposse/terraform-aws-service-quotas +cloudposse/terraform-aws-budgets +cloudposse/terraform-aws-ecr-public +cloudposse/terraform-aws-amplify-app +#cloudposse/terraform-provider-atmos +cloudposse/terraform-aws-glue +cloudposse/terraform-aws-github-action-token-rotator +cloudposse/terraform-aws-athena +cloudposse/terraform-aws-lakeformation +cloudposse/terraform-aws-kinesis-stream diff --git a/migrate/migrations/20240314/repos-10 b/migrate/migrations/20240314/repos-10 new file mode 100644 index 00000000..b2b2ad2f --- /dev/null +++ b/migrate/migrations/20240314/repos-10 @@ -0,0 +1,8 @@ +cloudposse/terraform-aws-dms +cloudposse/terraform-aws-ecs-cluster +cloudposse/terraform-aws-network-firewall +cloudposse/terraform-aws-route53-resolver-dns-firewall +cloudposse/terraform-module-test +cloudposse/terraform-aws-step-functions +cloudposse/terraform-aws-kv-store +cloudposse/terraform-aws-refarch-utils diff --git a/migrate/migrations/20240314/retry.txt b/migrate/migrations/20240314/retry.txt new file mode 100644 index 00000000..51f36baa --- /dev/null +++ b/migrate/migrations/20240314/retry.txt @@ -0,0 +1,2 @@ +cloudposse/terraform-aws-dynamic-subnets +cloudposse/terraform-aws-efs \ No newline at end of file diff --git a/migrate/migrations/20240314/script.sh b/migrate/migrations/20240314/script.sh new file mode 100644 index 00000000..4294b9c9 --- /dev/null +++ b/migrate/migrations/20240314/script.sh @@ -0,0 +1,6 @@ +title "Add GitHub Settings" + +install_github_settings + +# Merge the PR +auto_merge diff --git a/migrate/run.sh b/migrate/run.sh index 8c06adc8..a64359c4 100755 --- a/migrate/run.sh +++ b/migrate/run.sh @@ -21,6 +21,7 @@ migration=$1 migration_path=${MIGRATE_PATH}/migrations/$migration migration_script=${migration_path}/script.sh migration_readme=${migration_path}/README.md +curdir=$(pwd) if [ -z "${migration}" ]; then echo "Error: No migration specified" @@ -38,12 +39,20 @@ if [[ -z "$XARGS_DRY_RUN" || -z "$XARGS_REPO_NAME" || -z "$XARGS_REPO_OWNER" ]]; exit 1 fi +current_branch=$(git rev-parse --abbrev-ref HEAD) + +# Identify the default branch +default_branch=$(git remote show origin | grep 'HEAD branch' | cut -d' ' -f5) + +# Ensure our branch is reset to match the remote default branch, so that we can apply the migration cleanly +git reset --hard origin/${default_branch} + # Use migration's `.gitignore`, since not all repos have one git config --local core.excludesFile ${MIGRATE_PATH}/.gitignore # Clone the `build-harness` to a centralized location so we don't have to do it for every migration if [ ! -d "${MIGRATE_PATH}/tmp/build-harness" ]; then - git clone https://github.com/cloudposse/build-harness.git "${MIGRATE_PATH}/tmp/build-harness" + git clone https://github.com/cloudposse/build-harness.git "$(dirname ${curdir})/build-harness" fi # Load all the helper functions @@ -56,7 +65,6 @@ done # Export the repo type repo_type - if [ -d "${MIGRATE_PATH}/templates/${REPO_TYPE}" ]; then info "Using ${REPO_TYPE} repository type for (${XARGS_REPO_NAME})" else @@ -69,26 +77,47 @@ info "Starting migration $migration" source ${MIGRATE_PATH}/migrations/$migration/script.sh set +e -# Commit the changes -git commit -a --message "chore: ${TITLE}" -git push origin HEAD - # due to a bug in `git-xargs`, we need to clean up manually before exiting # https://github.com/gruntwork-io/git-xargs/issues/53 git clean -fxd +# Commit the changes +git commit -a --message "chore: ${TITLE}" + +# Get the differences between the current branch and the default branch +diff=$(git diff origin/${default_branch}...HEAD) + +# Check if there are any changes +if [ -z "$diff" ]; then + info "No changes relative to main; not creating a PR." + # Check if the remote branch exists + if git ls-remote --heads origin "${current_branch}" | grep -q "${current_branch}"; then + info "Remote branch exists. Deleting..." + git push origin --delete "${current_branch}" + fi + exit 0 +fi + +if [ "${current_branch}" != "${default_branch}" ]; then + git push origin HEAD --force +fi + if [ "${XARGS_DRY_RUN}" == "false" ]; then # First, we have to ensure labels already exist. They will not be created on-demand. create_labels # Create or update the pull request - gh pr create --title="${TITLE}" --body-file=${migration_readme} --label=${LABELS} || \ - gh pr edit --title="${TITLE}" --body-file=${migration_readme} --add-label=${LABELS} + gh pr create --title="${TITLE}" --body-file=${migration_readme} --label="${LABELS}" || \ + gh pr edit --title="${TITLE}" --body-file=${migration_readme} --add-label="${LABELS}" info "PR: $(gh pr view --json url --jq .url)" + gh pr view --json url --jq .url >> ${MIGRATE_PATH}/pr.log # Automatically merge this PR after checks pass, using admin privileges to bypass branch protections. # Then delete the branch. if [ "${AUTO_MERGE}" == "true" ]; then info "Auto-merging PR" - gh pr merge --auto --squash --delete-branch + gh pr merge --admin --squash --delete-branch fi fi + +# Clean up again, so that `git-xargs` doesn't commit the cache files from `gh` cli in the `tmp/` folder +git clean -fxd \ No newline at end of file diff --git a/migrate/templates/terraform-module/.github/renovate.json b/migrate/templates/terraform-module/.github/renovate.json new file mode 100644 index 00000000..64ae6e33 --- /dev/null +++ b/migrate/templates/terraform-module/.github/renovate.json @@ -0,0 +1,5 @@ +{ + "extends": [ + "github>cloudposse/.github" + ] +} \ No newline at end of file diff --git a/migrate/yamlfix.toml b/migrate/yamlfix.toml deleted file mode 100644 index cc03288e..00000000 --- a/migrate/yamlfix.toml +++ /dev/null @@ -1,7 +0,0 @@ -allow_duplicate_keys = false -line_length = 100 -comments_min_spaces_from_content = 2 -comments_require_starting_space = true -whitelines = 2 -section_whitelines = 1 -comments_whitelines = 2