Skip to content

Commit 3b96e0c

Browse files
authored
Merge pull request #95 from dflook/optional-path
Use the action workspace by default
2 parents 23e3498 + 5409929 commit 3b96e0c

File tree

24 files changed

+72
-32
lines changed

24 files changed

+72
-32
lines changed

.github/workflows/test-plan.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,20 @@ jobs:
329329
TERRAFORM_PRE_RUN: |
330330
echo "testing command 1"
331331
echo "testing command 2"
332+
333+
default_path:
334+
runs-on: ubuntu-latest
335+
name: Default path
336+
env:
337+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
338+
steps:
339+
- name: Checkout
340+
uses: actions/checkout@v2
341+
342+
- name: Copy
343+
run: cp tests/plan/plan/main.tf ./main.tf
344+
345+
- name: Plan
346+
uses: ./terraform-plan
347+
with:
348+
label: Optional path

image/tools/github_pr_comment.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
github_url = os.environ.get('GITHUB_SERVER_URL', 'https://github.com')
1919
github_api_url = os.environ.get('GITHUB_API_URL', 'https://api.github.com')
2020

21-
def github_api_request(method, *args, **kw_args):
22-
response = github.request(method, *args, **kw_args)
21+
def github_api_request(method, *args, **kwargs):
22+
response = github.request(method, *args, **kwargs)
2323

2424
if 400 <= response.status_code < 500:
2525
debug(str(response.headers))
@@ -49,21 +49,23 @@ def debug(msg: str) -> None:
4949
sys.stderr.write(msg)
5050
sys.stderr.write('\n')
5151

52-
def prs(repo: str) -> Iterable[Dict]:
53-
url = f'{github_api_url}/repos/{repo}/pulls'
52+
def paginate(url, *args, **kwargs) -> Iterable[Dict]:
5453

5554
while True:
56-
response = github_api_request('get', url, params={'state': 'all'})
55+
response = github_api_request('get', url, *args, **kwargs)
5756
response.raise_for_status()
5857

59-
for pr in response.json():
60-
yield pr
58+
yield from response.json()
6159

6260
if 'next' in response.links:
6361
url = response.links['next']['url']
6462
else:
6563
return
6664

65+
def prs(repo: str) -> Iterable[Dict]:
66+
url = f'{github_api_url}/repos/{repo}/pulls'
67+
yield from paginate(url, params={'state': 'all'})
68+
6769

6870
def find_pr() -> str:
6971
"""
@@ -152,13 +154,12 @@ def __init__(self, pr_url: str=None):
152154
response.raise_for_status()
153155

154156
self._issue_url = response.json()['_links']['issue']['href'] + '/comments'
155-
response = github_api_request('get', self._issue_url)
156-
response.raise_for_status()
157157

158158
username = current_user()
159159

160160
debug('Looking for an existing comment:')
161-
for comment in response.json():
161+
162+
for comment in paginate(self._issue_url):
162163
debug(json.dumps(comment))
163164
if comment['user']['login'] == username:
164165
match = re.match(rf'{re.escape(self._comment_identifier)}.*```(?:hcl)?(.*?)```.*', comment['body'], re.DOTALL)

terraform-apply/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ These input values must be the same as any `terraform-plan` for the same configu
3838
Path to the terraform configuration to apply
3939

4040
- Type: string
41-
- Required
41+
- Optional
42+
- Default: The action workspace
4243

4344
* `workspace`
4445

terraform-apply/action.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ author: Daniel Flook
55
inputs:
66
path:
77
description: Path to the terraform configuration
8-
required: true
8+
required: false
9+
default: .
910
workspace:
1011
description: Name of the terraform workspace
1112
required: false

terraform-check/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ This is intended to run on a schedule to notify if manual changes to your infras
1313
Path to the terraform configuration to check
1414

1515
- Type: string
16-
- Required
16+
- Optional
17+
- Default: The action workspace
1718

1819
* `workspace`
1920

terraform-check/action.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ author: Daniel Flook
55
inputs:
66
path:
77
description: Path to the terraform configuration
8-
required: true
8+
required: false
9+
default: .
910
workspace:
1011
description: Name of the terraform workspace
1112
required: false

terraform-destroy-workspace/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ This action uses the `terraform destroy` command to destroy all resources in a t
1111
Path to the terraform configuration
1212

1313
- Type: string
14-
- Required
14+
- Optional
15+
- Default: The action workspace
1516

1617
* `workspace`
1718

terraform-destroy-workspace/action.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ author: Daniel Flook
55
inputs:
66
path:
77
description: Path to the terraform configuration
8-
required: true
8+
required: false
9+
default: .
910
workspace:
1011
description: Name of the terraform workspace
1112
required: true

terraform-destroy/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ This action uses the `terraform destroy` command to destroy all resources in a t
1212
Path to the terraform configuration
1313

1414
- Type: string
15-
- Required
15+
- Optional
16+
- Default: The action workspace
1617

1718
* `workspace`
1819

terraform-destroy/action.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ author: Daniel Flook
55
inputs:
66
path:
77
description: Path to the terraform configuration
8-
required: true
8+
required: false
9+
default: .
910
workspace:
1011
description: Name of the terraform workspace
1112
required: false

terraform-fmt-check/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ If any files are not correctly formatted a failing GitHub check will be added fo
1414
Path to the terraform configuration
1515

1616
- Type: string
17-
- Required
17+
- Optional
18+
- Default: The action workspace
1819

1920
## Example usage
2021

terraform-fmt-check/action.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ author: Daniel Flook
55
inputs:
66
path:
77
description: Path to the terraform configuration
8-
required: true
8+
required: false
9+
default: .
910

1011
runs:
1112
using: docker

terraform-fmt/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ This action uses the `terraform fmt` command to reformat files in a directory in
1111
Path to the terraform configuration
1212

1313
- Type: string
14-
- Required
14+
- Optional
15+
- Default: The action workspace
1516

1617
## Example usage
1718

terraform-fmt/action.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ author: Daniel Flook
55
inputs:
66
path:
77
description: Path to the terraform configuration
8-
required: true
8+
required: false
9+
default: .
910

1011
runs:
1112
using: docker

terraform-new-workspace/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Creates a new terraform workspace. If the workspace already exists, succeeds wit
1111
Path to the terraform configuration
1212

1313
- Type: string
14-
- Required
14+
- Optional
15+
- Default: The action workspace
1516

1617
* `workspace`
1718

terraform-new-workspace/action.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ author: Daniel Flook
55
inputs:
66
path:
77
description: Path to the terraform configuration
8-
required: true
8+
required: false
9+
default: .
910
workspace:
1011
description: Name of the terraform workspace
1112
required: true

terraform-output/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Retrieve the root-level outputs from a terraform configuration.
1111
Path to the terraform configuration
1212

1313
- Type: string
14-
- Required
14+
- Optional
15+
- Default: The action workspace
1516

1617
* `workspace`
1718

terraform-output/action.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ author: Daniel Flook
55
inputs:
66
path:
77
description: Path to the terraform configuration
8-
required: true
8+
required: false
9+
default: .
910
workspace:
1011
description: Name of the terraform workspace
1112
required: false

terraform-plan/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ The [dflook/terraform-apply](https://github.com/dflook/terraform-github-actions/
2121
Path to the terraform configuration
2222

2323
- Type: string
24-
- Required
24+
- Optional
25+
- Default: The action workspace
2526

2627
* `workspace`
2728

terraform-plan/action.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ author: Daniel Flook
55
inputs:
66
path:
77
description: Path to the terraform configuration
8-
required: true
8+
required: false
9+
default: .
910
workspace:
1011
description: Name of the terraform workspace
1112
required: false

terraform-validate/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ If the terraform configuration is not valid, the build is failed.
2020
Path to the terraform configuration
2121

2222
- Type: string
23-
- Required
23+
- Optional
24+
- Default: The action workspace
2425

2526
## Environment Variables
2627

terraform-validate/action.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ author: Daniel Flook
55
inputs:
66
path:
77
description: Path to the terraform configuration
8-
required: true
8+
required: false
9+
default: .
910

1011
runs:
1112
using: docker

terraform-version/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ outputs yourself.
2525
Path to the terraform configuration to apply
2626

2727
- Type: string
28-
- Required
28+
- Optional
29+
- Default: The action workspace
2930

3031
## Environment Variables
3132

terraform-version/action.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ author: Daniel Flook
55
inputs:
66
path:
77
description: Path to the terraform configuration
8-
required: true
8+
required: false
9+
default: .
910

1011
outputs:
1112
version:

0 commit comments

Comments
 (0)