Skip to content

Commit

Permalink
(feature): scripts (#55) [norelease]
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgreg31 authored May 27, 2023
1 parent 9208c3e commit 813c29e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bump.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Version Bump
name: Build
on:
push:
branches:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ jobs:
run: terraform fmt
continue-on-error: true
shell: bash
- name: Terraform Setup
id: setup
run: python ${{ env.WORK_DIR }}/scripts/staging.py
shell: bash
- name: Terraform Init
id: init
run: |
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- 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)
![Build Status](https://github.com/jmgreg31/terraform-aws-cloudfront/actions/workflows/bump.yml/badge.svg?event=push)
[![Latest Release](https://img.shields.io/badge/release-v4.3.8-blue.svg)](https://github.com/jmgreg31/terraform-aws-cloudfront/releases/tag/v4.3.8)

# Terraform Cloudfront Module
Expand Down
20 changes: 11 additions & 9 deletions bump.py → scripts/bump.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
import os
import re

WORK_DIR = os.getenv("WORK_DIR")


def get_version() -> str:
with open("VERSION", "r") as version:
with open(f"{WORK_DIR}/VERSION", "r") as version:
for line in version:
output = line
bumpversion = "v" + output
return bumpversion.rstrip()


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


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


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


Expand All @@ -39,10 +41,10 @@ def update_example() -> None:
bumpversion
)
)
data = get_data("example/main.tf", r"source[ \t]+\=.*", replacement)
with open("example/main.tf", "w") as newfile:
data = get_data(f"{WORK_DIR}/example/main.tf", r"source[ \t]+\=.*", replacement)
with open(f"{WORK_DIR}/example/main.tf", "w") as newfile:
newfile.write(data)
os.system("./terraform fmt example/")
os.system(f"./terraform fmt {WORK_DIR}/example/")


def push_changes() -> None:
Expand Down
21 changes: 21 additions & 0 deletions scripts/staging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os
import re

WORK_DIR = os.getenv("WORK_DIR")


def update_file(path: str, expression: str, replacement: str) -> None:
with open(path, "r") as readme:
data = readme.read()
data = re.sub(expression, replacement, data)
with open(path, "w") as newfile:
newfile.write(data)


def update_example() -> None:
replacement = 'source = "../"'
update_file(f"{WORK_DIR}/example/main.tf", r"source[ \t]+\=.*", replacement)


if __name__ == "__main__":
update_example()

0 comments on commit 813c29e

Please sign in to comment.