Skip to content

Commit

Permalink
(feature): simplify contribution, fix github actions (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgreg31 authored May 27, 2023
1 parent a164a9b commit 4c2b4c0
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 115 deletions.
38 changes: 23 additions & 15 deletions .github/workflows/bump.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,27 @@ jobs:
runs-on: ubuntu-latest
environment: VERSION_BUMP
steps:
- name: Check-Out
uses: actions/checkout@v2
with:
repository: jmgreg31/terraform-aws-cloudfront
token: ${{ secrets.GH_TOKEN }}
path: ${{ env.WORK_DIR }}
- name: Check-Out
uses: actions/checkout@v2
with:
repository: jmgreg31/terraform-aws-cloudfront
token: ${{ secrets.GH_TOKEN }}
path: ${{ env.WORK_DIR }}

- name: Bump Version
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
cd ${{ env.WORK_DIR }}
wget https://releases.hashicorp.com/terraform/0.13.1/terraform_0.13.1_linux_amd64.zip
unzip terraform_0.13.1_linux_amd64.zip
python bump.py
shell: bash
- name: Bump Version
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
cd ${{ env.WORK_DIR }}
wget https://releases.hashicorp.com/terraform/0.13.1/terraform_0.13.1_linux_amd64.zip
unzip terraform_0.13.1_linux_amd64.zip
python bump.py
shell: bash

# Use [norelease] or release:major | minor | patch to override
- name: Release
uses: rymndhng/release-on-push-action@v0.28.0
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
with:
bump_version_scheme: patch
73 changes: 36 additions & 37 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,52 @@ name: Terraform - Staging
on:
pull_request:
branches:
- "staging"
- "master"
env:
WORK_DIR: terraform-cloudfront

permissions:
contents: read
pull-requests: write

jobs:
jobs:
terraform:
runs-on: ubuntu-latest
name: Terraform
environment: TERRAFORM_STAGING
steps:
- name: Check-Out
uses: actions/checkout@v2
with:
repository: jmgreg31/terraform-aws-cloudfront
token: ${{ secrets.GITHUB_TOKEN }}
path: ${{ env.WORK_DIR }}

- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 0.13.1
terraform_wrapper: false
- name: Terraform Format
id: fmt
run: terraform fmt
continue-on-error: true
shell: bash
- name: Terraform Init
id: init
run: |
cd ${{ env.WORK_DIR }}/example/
terraform init
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
shell: bash
- name: Terraform Plan
id: plan
run: |
cd ${{ env.WORK_DIR }}/example/
terraform plan
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
shell: bash
- name: Check-Out
uses: actions/checkout@v2
with:
repository: jmgreg31/terraform-aws-cloudfront
token: ${{ secrets.GITHUB_TOKEN }}
path: ${{ env.WORK_DIR }}

- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 0.13.1
terraform_wrapper: false
- name: Terraform Format
id: fmt
run: terraform fmt
continue-on-error: true
shell: bash
- name: Terraform Init
id: init
run: |
cd ${{ env.WORK_DIR }}/example/
terraform init
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
shell: bash
- name: Terraform Plan
id: plan
run: |
cd ${{ env.WORK_DIR }}/example/
terraform plan
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
shell: bash
14 changes: 11 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
## v4.3.6 (February 2023)
<!-- markdownlint-disable MD041 -->
## UNRELEASED (May 2023)

* Update `default_cache_behavior` and `dynamic_ordered_cache_behavior` with ability to accept `response_headers_policy_id`(UUID) parameter.
* Simplify Contribution Workflow
* Fix GitHub Actions

## v4.3.7 (May 2023)

## v4.3.6 (Feb 2023)
* Update `version.tf` to support aws provider >= 3.41

## v4.3.6 (February 2023)

* Update `default_cache_behavior` and `dynamic_ordered_cache_behavior` with ability to accept `response_headers_policy_id`(UUID) parameter.

* Move from Travis CI to GitHub Actions

## v4.3.5 (June 2021)
Expand Down
9 changes: 5 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ Contributions are open and welcome! Please follow the guidelines below.

## Pull Request Process

Submit a PR to the `staging` branch
Submit a PR to the `master` branch

1. Update `README.md` documentation with any applicable changes.
2. Update `CHANGELOG.md` with the details of the change. Please follow the format below:

1. Update the README.md with details of changes.
2. Update the CHANGELOG.md with the details of the change. Please follow the format below:
```sh
## UNRELEASED (<MONTH><YEAR>)
```

3. Update the [VERSION](https://github.com/jmgreg31/terraform-aws-cloudfront/blob/master/VERSION) numbers to the new version that this Pull Request would represent. The versioning scheme used is [SemVer](http://semver.org/).
4. Update the [EXAMPLE](https://github.com/jmgreg31/terraform-aws-cloudfront/blob/master/example) terraform to reflect your changes. Please make sure the [SOURCE](https://github.com/jmgreg31/terraform-aws-cloudfront/blob/master/example/main.tf#L142) is `git::https://github.com/jmgreg31/terraform-aws-cloudfront.git?ref=staging`

## Testing

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<!-- markdownlint-disable MD033 -->
<!-- markdownlint-disable MD041 -->
[![Build Status](https://travis-ci.com/jmgreg31/terraform-aws-cloudfront.svg?branch=master)](https://travis-ci.com/jmgreg31/terraform-aws-cloudfront)
[![Latest Release](https://img.shields.io/badge/release-v4.3.7-blue.svg)](https://github.com/jmgreg31/terraform-aws-cloudfront/releases/tag/v4.3.7)

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.3.7
4.3.8
94 changes: 55 additions & 39 deletions bump.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,67 @@
import re
import os
import re


def getVersion():
with open ('VERSION','r') as version:
def get_version() -> str:
with open("VERSION", "r") as version:
for line in version:
output=line
bumpversion='v'+ output
output = line
bumpversion = "v" + output
return bumpversion.rstrip()

def getData(filename,expression,replacement):
with open (filename, 'r') as readme:
data=readme.read()
data=re.sub(expression, replacement, data)

def get_data(filename: str, expression: str, replacement: str) -> str:
with open(filename, "r") as readme:
data = readme.read()
data = re.sub(expression, replacement, data)
return data

def updateREADME():
bumpversion = getVersion()
data=getData('README.md',r'v\d+\.\d+\.\d+',bumpversion)
with open ('README.md', 'w') as newfile:

def update_readme() -> None:
bumpversion = get_version()
data = get_data("README.md", r"v\d+\.\d+\.\d+", bumpversion)
with open("README.md", "w") as newfile:
newfile.write(data)

def updateCHANGELOG():
bumpversion = getVersion()
data=getData('CHANGELOG.md',r'UNRELEASED',bumpversion)
with open ('CHANGELOG.md', 'w') as newfile:

def update_changelog() -> None:
bumpversion = get_version()
data = get_data("CHANGELOG.md", r"UNRELEASED", bumpversion)
with open("CHANGELOG.md", "w") as newfile:
newfile.write(data)

def updateMaintf():
bumpversion = getVersion()
replacement = "source = " + "\"git::https://github.com/jmgreg31/terraform-aws-cloudfront.git?ref={}\"".format(bumpversion)
data=getData('example/main.tf',r'source[ \t]+\=.*',replacement)
with open ('example/main.tf', 'w') as newfile:

def update_example() -> None:
bumpversion = get_version()
replacement = (
"source = "
+ '"git::https://github.com/jmgreg31/terraform-aws-cloudfront.git?ref={}"'.format(
bumpversion
)
)
data = get_data("example/main.tf", r"source[ \t]+\=.*", replacement)
with open("example/main.tf", "w") as newfile:
newfile.write(data)
os.system('./terraform fmt example/')

def updateGit():
bumpversion = getVersion()
os.system('git config --global user.email \"jmgreg31@gmail.com\" && \
git config --global user.name "Jon Greg"')
os.system('git checkout master')
os.system('git add README.md CHANGELOG.md example/main.tf example/terraform.tfvars')
os.system('git commit -m "Bump Version to {}"'.format(bumpversion))
os.system('git remote set-url origin https://jmgreg31:${GH_TOKEN}@github.com/jmgreg31/terraform-aws-cloudfront.git > /dev/null 2>&1')
os.system('git push origin master')

if __name__ == '__main__':
updateREADME()
updateCHANGELOG()
updateMaintf()
updateGit()
os.system("./terraform fmt example/")


def push_changes() -> None:
bumpversion = get_version()
os.system(
'git config --global user.email "jmgreg31@gmail.com" && \
git config --global user.name "Jon Greg"'
)
os.system("git checkout master")
os.system("git add README.md CHANGELOG.md example/main.tf example/terraform.tfvars")
os.system('git commit -m "(ci): Bump Version to {}"'.format(bumpversion))
os.system(
"git remote set-url origin https://jmgreg31:${GH_TOKEN}@github.com/jmgreg31/terraform-aws-cloudfront.git > /dev/null 2>&1"
)
os.system("git push origin master")


if __name__ == "__main__":
update_readme()
update_changelog()
update_example()
push_changes()
9 changes: 6 additions & 3 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Module Example
This is an example of the AWS Cloudfront Distribution with the module in use. The `main.tf` exhibits the module definition. Pay special attention to the `source` variable, as it is calling a specific reference tag of the module. It is highly encouraged to follow the same pattern to avoid any breaking changes as updates to the module are released. Please note the syntax of the variable definitions in the `terraform.tfvars` file for adding and removing multiple items.

This is an example of the AWS Cloudfront Distribution with the module in use. The `main.tf` exhibits the module definition. Pay special attention to the `source` variable, as it is calling a specific reference tag of the module. It is highly encouraged to follow the same pattern to avoid any breaking changes as updates to the module are released. Please note the syntax of the variable definitions in the `terraform.tfvars` file for adding and removing multiple items.

## Terraform Backend

It may be important to store the state of the terraform configuration remotely. This will ensure that your resources can be referenced from multiple locations. If you too feel this is important **PLEASE** be sure to update the [Terraform-Backend](https://github.com/jmgreg31/terraform-aws-cloudfront/blob/master/example/main.tf#L119-L126) section in your configuration where:

* `bucket` = Your S3 bucket
Expand All @@ -12,10 +14,11 @@ It may be important to store the state of the terraform configuration remotely.
Otherwise, this section can be removed. Due to terraform limitations, these can not be variables within the configuration. However, terraform does offer a way to pass these variables in at runtime.

Example:
```

```sh
terraform init \
-backend-config="bucket=my-bucket" \
-backend-config="key=cloudfront/terraform.tfstate" \
-backend-config="region=us-east-1" \
-backend-config="encrypt=true"
```
```
2 changes: 1 addition & 1 deletion example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ terraform {
}

provider "aws" {
version = ">= 3.0.0"
version = ">= 3.41"
region = var.region
}

Expand Down
24 changes: 12 additions & 12 deletions example/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,18 @@ dynamic_ordered_cache_behavior = [
]
},
{
path_pattern = "/test2/"
allowed_methods = ["GET", "HEAD"]
cached_methods = ["GET", "HEAD"]
target_origin_id = "S3-domain-cert"
compress = false
query_string = true
cookies_forward = "all"
headers = []
viewer_protocol_policy = "redirect-to-https"
min_ttl = 0
default_ttl = 0
max_ttl = 0
path_pattern = "/test2/"
allowed_methods = ["GET", "HEAD"]
cached_methods = ["GET", "HEAD"]
target_origin_id = "S3-domain-cert"
compress = false
query_string = true
cookies_forward = "all"
headers = []
viewer_protocol_policy = "redirect-to-https"
min_ttl = 0
default_ttl = 0
max_ttl = 0
response_headers_policy_id = "60669652-455b-4ae9-85a4-c4c02393f86c"
}
]
Expand Down

0 comments on commit 4c2b4c0

Please sign in to comment.