Skip to content

Commit

Permalink
feat: artifact support pattern and merge_multiple (#139)
Browse files Browse the repository at this point in the history
* artifact-support-pattern

* fix-artifact-env
  • Loading branch information
DCamma authored Oct 24, 2024
1 parent 150d49f commit 5fb7e98
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 11 deletions.
20 changes: 15 additions & 5 deletions .github/workflows/docker-build-push-ecr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ on:
artifact_path:
description: "Artifact target path"
type: string
artifact_pattern:
description: "A glob pattern to the artifacts that should be downloaded. Ignored if name is specified."
type: string
artifact_merge_multiple:
description: "When multiple artifacts are matched, this changes the behavior of the destination directories. If true, the downloaded artifacts will be in the same directory specified by path. If false, the downloaded artifacts will be extracted into individual named directories within the specified path. Optional. Default is 'false'."
type: boolean
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -58,15 +64,19 @@ jobs:
- name: Check out code
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4

- name: Download artifacts to pass to docker build
if: ${{ inputs.artifact_name || inputs.artifact_path }} # avoid downloading artifacts if not needed
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
- name: Download Artifacts
env:
ARTIFACT_NAME: ${{ inputs.artifact_name || vars.artifact_name }}
ARTIFACT_PATH: ${{ inputs.artifact_path || vars.artifact_path }}
ARTIFACT_NAME: ${{ inputs.artifact_name || vars.artifact_name }}
ARTIFACT_PATTERN: ${{ inputs.artifact_pattern || vars.artifact_pattern }}
ARTIFACT_MERGE_MULTIPLE: ${{ inputs.artifact_merge_multiple || vars.artifact_merge_multiple || false}}
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
if: env.ARTIFACT_PATH != '' || env.ARTIFACT_NAME != ''
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.ARTIFACT_PATH }}
name: ${{ env.ARTIFACT_NAME }}
pattern: ${{ env.ARTIFACT_PATTERN }}
merge-multiple: ${{ env.ARTIFACT_MERGE_MULTIPLE }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3
Expand Down
14 changes: 12 additions & 2 deletions .github/workflows/tf-apply.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ on:
gh_checkout_ref:
description: "The branch, tag or SHA to checkout."
type: string
gh_artifact_pattern:
description: "A glob pattern to the artifacts that should be downloaded. Ignored if name is specified."
type: string
gh_artifact_merge_multiple:
description: "When multiple artifacts are matched, this changes the behavior of the destination directories. If true, the downloaded artifacts will be in the same directory specified by path. If false, the downloaded artifacts will be extracted into individual named directories within the specified path. Optional. Default is 'false'."
type: boolean
tf_dir:
description: "Path to the Terraform root module to apply."
type: string
Expand Down Expand Up @@ -86,13 +92,17 @@ jobs:

- name: Download Artifacts
env:
GH_ARTIFACT_PATH: ${{ inputs.gh_artifact_path || vars.gh_artifact_path || '' }}
GH_ARTIFACT_NAME: ${{ inputs.gh_artifact_name || vars.gh_artifact_name || '' }}
GH_ARTIFACT_PATH: ${{ inputs.gh_artifact_path || vars.gh_artifact_path }}
GH_ARTIFACT_NAME: ${{ inputs.gh_artifact_name || vars.gh_artifact_name }}
GH_ARTIFACT_PATTERN: ${{ inputs.gh_artifact_pattern || vars.gh_artifact_pattern }}
GH_ARTIFACT_MERGE_MULTIPLE: ${{ inputs.gh_artifact_merge_multiple || vars.gh_artifact_merge_multiple || false }}
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
if: env.GH_ARTIFACT_PATH != '' || env.GH_ARTIFACT_NAME != ''
with:
path: ${{ env.GH_ARTIFACT_PATH }}
name: ${{ env.GH_ARTIFACT_NAME }}
pattern: ${{ env.GH_ARTIFACT_PATTERN }}
merge-multiple: ${{ env.GH_ARTIFACT_MERGE_MULTIPLE }}

- name: Terraform Apply
id: tf_apply
Expand Down
14 changes: 12 additions & 2 deletions .github/workflows/tf-feature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ on:
gh_checkout_ref:
description: "The branch, tag or SHA to checkout."
type: string
gh_artifact_pattern:
description: "A glob pattern to the artifacts that should be downloaded. Ignored if name is specified."
type: string
gh_artifact_merge_multiple:
description: "When multiple artifacts are matched, this changes the behavior of the destination directories. If true, the downloaded artifacts will be in the same directory specified by path. If false, the downloaded artifacts will be extracted into individual named directories within the specified path. Optional. Default is 'false'."
type: boolean
tf_dir:
description: "Terraform directory"
type: string
Expand Down Expand Up @@ -92,13 +98,17 @@ jobs:

- name: Download Artifacts
env:
GH_ARTIFACT_PATH: ${{ inputs.gh_artifact_path || vars.gh_artifact_path || '' }}
GH_ARTIFACT_NAME: ${{ inputs.gh_artifact_name || vars.gh_artifact_name || '' }}
GH_ARTIFACT_PATH: ${{ inputs.gh_artifact_path || vars.gh_artifact_path }}
GH_ARTIFACT_NAME: ${{ inputs.gh_artifact_name || vars.gh_artifact_name }}
GH_ARTIFACT_PATTERN: ${{ inputs.gh_artifact_pattern || vars.gh_artifact_pattern }}
GH_ARTIFACT_MERGE_MULTIPLE: ${{ inputs.gh_artifact_merge_multiple || vars.gh_artifact_merge_multiple || false }}
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
if: env.GH_ARTIFACT_PATH != '' || env.GH_ARTIFACT_NAME != ''
with:
path: ${{ env.GH_ARTIFACT_PATH }}
name: ${{ env.GH_ARTIFACT_NAME }}
pattern: ${{ env.GH_ARTIFACT_PATTERN }}
merge-multiple: ${{ env.GH_ARTIFACT_MERGE_MULTIPLE }}

- name: Use Branch Workspace
uses: dflook/terraform-new-workspace@328d939679a5ddd00425d9cd75ceb6689f54c2bc # v1
Expand Down
14 changes: 12 additions & 2 deletions .github/workflows/tf-plan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ on:
gh_checkout_ref:
description: "The branch, tag or SHA to checkout."
type: string
gh_artifact_pattern:
description: "A glob pattern to the artifacts that should be downloaded. Ignored if name is specified."
type: string
gh_artifact_merge_multiple:
description: "When multiple artifacts are matched, this changes the behavior of the destination directories. If true, the downloaded artifacts will be in the same directory specified by path. If false, the downloaded artifacts will be extracted into individual named directories within the specified path. Optional. Default is 'false'."
type: boolean
gh_comment:
description: "Whether to post a comment on the PR with the Terraform plan"
type: string
Expand Down Expand Up @@ -86,13 +92,17 @@ jobs:

- name: Download Artifacts
env:
GH_ARTIFACT_PATH: ${{ inputs.gh_artifact_path || vars.gh_artifact_path || '' }}
GH_ARTIFACT_NAME: ${{ inputs.gh_artifact_name || vars.gh_artifact_name || '' }}
GH_ARTIFACT_PATH: ${{ inputs.gh_artifact_path || vars.gh_artifact_path }}
GH_ARTIFACT_NAME: ${{ inputs.gh_artifact_name || vars.gh_artifact_name }}
GH_ARTIFACT_PATTERN: ${{ inputs.gh_artifact_pattern || vars.gh_artifact_pattern }}
GH_ARTIFACT_MERGE_MULTIPLE: ${{ inputs.gh_artifact_merge_multiple || vars.gh_artifact_merge_multiple || false }}
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
if: env.GH_ARTIFACT_PATH != '' || env.GH_ARTIFACT_NAME != ''
with:
path: ${{ env.GH_ARTIFACT_PATH }}
name: ${{ env.GH_ARTIFACT_NAME }}
pattern: ${{ env.GH_ARTIFACT_PATTERN }}
merge-multiple: ${{ env.GH_ARTIFACT_MERGE_MULTIPLE }}

- name: Terraform Format
uses: dflook/terraform-fmt-check@c9309dc072b71dded0f23b29e3ffd4406e27c078 # v1
Expand Down
16 changes: 16 additions & 0 deletions docs/workflows/docker-build-push-ecr.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ This workflow builds a Docker image and pushes it to the Elastic Container Regis
| `docker_target` | <p>Build target</p> | `string` | `false` | `""` |
| `artifact_name` | <p>Artifact name to be downloaded before building</p> | `string` | `false` | `""` |
| `artifact_path` | <p>Artifact target path</p> | `string` | `false` | `""` |
| `artifact_pattern` | <p>A glob pattern to the artifacts that should be downloaded. Ignored if name is specified.</p> | `string` | `false` | `""` |
| `artifact_merge_multiple` | <p>When multiple artifacts are matched, this changes the behavior of the destination directories. If true, the downloaded artifacts will be in the same directory specified by path. If false, the downloaded artifacts will be extracted into individual named directories within the specified path. Optional. Default is 'false'.</p> | `boolean` | `false` | `""` |
<!-- action-docs-inputs source=".github/workflows/docker-build-push-ecr.yaml" -->

<!-- action-docs-outputs source=".github/workflows/docker-build-push-ecr.yaml" -->
Expand Down Expand Up @@ -132,6 +134,20 @@ jobs:
# Type: string
# Required: false
# Default: ""

artifact_pattern:
# A glob pattern to the artifacts that should be downloaded. Ignored if name is specified.
#
# Type: string
# Required: false
# Default: ""

artifact_merge_multiple:
# When multiple artifacts are matched, this changes the behavior of the destination directories. If true, the downloaded artifacts will be in the same directory specified by path. If false, the downloaded artifacts will be extracted into individual named directories within the specified path. Optional. Default is 'false'.
#
# Type: boolean
# Required: false
# Default: ""
```
<!-- action-docs-usage source=".github/workflows/docker-build-push-ecr.yaml" project="tx-pts-dai/github-workflows/.github/workflows/docker-build-push-ecr.yaml" version="v1" -->

Expand Down
16 changes: 16 additions & 0 deletions docs/workflows/tf-apply.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ This workflow applies the Terraform configuration.
| `gh_artifact_path` | <p>Path to download artifacts to. If unset, default action workspace is used. If both 'gh<em>artifact</em>path' and 'gh<em>artifact</em>name' are unset, artifacts are not downloaded.</p> | `string` | `false` | `""` |
| `gh_artifact_name` | <p>Name of the artifact to download. If only 'gh<em>artifact</em>path' is set, then all artifacts are downloaded. If both 'gh<em>artifact</em>path' and 'gh<em>artifact</em>name' are unset, artifacts are not downloaded.</p> | `string` | `false` | `""` |
| `gh_checkout_ref` | <p>The branch, tag or SHA to checkout.</p> | `string` | `false` | `""` |
| `gh_artifact_pattern` | <p>A glob pattern to the artifacts that should be downloaded. Ignored if name is specified.</p> | `string` | `false` | `""` |
| `gh_artifact_merge_multiple` | <p>When multiple artifacts are matched, this changes the behavior of the destination directories. If true, the downloaded artifacts will be in the same directory specified by path. If false, the downloaded artifacts will be extracted into individual named directories within the specified path. Optional. Default is 'false'.</p> | `boolean` | `false` | `""` |
| `tf_dir` | <p>Path to the Terraform root module to apply.</p> | `string` | `false` | `""` |
| `tf_backend_configs` | <p>ist of Terraform backend config values, one per line.</p> | `string` | `false` | `""` |
| `tf_backend_config_files` | <p>List of Terraform backend config files to use, one per line. Paths should be relative to the GitHub Actions workspace.</p> | `string` | `false` | `""` |
Expand Down Expand Up @@ -103,6 +105,20 @@ jobs:
# Required: false
# Default: ""

gh_artifact_pattern:
# A glob pattern to the artifacts that should be downloaded. Ignored if name is specified.
#
# Type: string
# Required: false
# Default: ""

gh_artifact_merge_multiple:
# When multiple artifacts are matched, this changes the behavior of the destination directories. If true, the downloaded artifacts will be in the same directory specified by path. If false, the downloaded artifacts will be extracted into individual named directories within the specified path. Optional. Default is 'false'.
#
# Type: boolean
# Required: false
# Default: ""

tf_dir:
# Path to the Terraform root module to apply.
#
Expand Down
16 changes: 16 additions & 0 deletions docs/workflows/tf-feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ This workflow deploys a Terraform configuration to a preview environment.
| `gh_artifact_path` | <p>Path to download artifacts to. If unset, default action workspace is used. If both 'gh<em>artifact</em>path' and 'gh<em>artifact</em>name' are unset, artifacts are not downloaded.</p> | `string` | `false` | `""` |
| `gh_artifact_name` | <p>Name of the artifact to download. If only 'gh<em>artifact</em>path' is set, then all artifacts are downloaded. If both 'gh<em>artifact</em>path' and 'gh<em>artifact</em>name' are unset, artifacts are not downloaded.</p> | `string` | `false` | `""` |
| `gh_checkout_ref` | <p>The branch, tag or SHA to checkout.</p> | `string` | `false` | `""` |
| `gh_artifact_pattern` | <p>A glob pattern to the artifacts that should be downloaded. Ignored if name is specified.</p> | `string` | `false` | `""` |
| `gh_artifact_merge_multiple` | <p>When multiple artifacts are matched, this changes the behavior of the destination directories. If true, the downloaded artifacts will be in the same directory specified by path. If false, the downloaded artifacts will be extracted into individual named directories within the specified path. Optional. Default is 'false'.</p> | `boolean` | `false` | `""` |
| `tf_dir` | <p>Terraform directory</p> | `string` | `false` | `""` |
| `tf_backend_configs` | <p>Terraform backend config cli arguments</p> | `string` | `false` | `""` |
| `tf_backend_config_files` | <p>List of Terraform backend config files to use, one per line. Paths should be relative to the GitHub Actions workspace.</p> | `string` | `false` | `""` |
Expand Down Expand Up @@ -96,6 +98,20 @@ jobs:
# Required: false
# Default: ""

gh_artifact_pattern:
# A glob pattern to the artifacts that should be downloaded. Ignored if name is specified.
#
# Type: string
# Required: false
# Default: ""

gh_artifact_merge_multiple:
# When multiple artifacts are matched, this changes the behavior of the destination directories. If true, the downloaded artifacts will be in the same directory specified by path. If false, the downloaded artifacts will be extracted into individual named directories within the specified path. Optional. Default is 'false'.
#
# Type: boolean
# Required: false
# Default: ""

tf_dir:
# Terraform directory
#
Expand Down
16 changes: 16 additions & 0 deletions docs/workflows/tf-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ This workflow runs `terraform plan` and uploads the plan to Github Action summar
| `gh_artifact_path` | <p>Path to download artifacts to. If unset, default action workspace is used. If both 'gh<em>artifact</em>path' and 'gh<em>artifact</em>name' are unset, artifacts are not downloaded.</p> | `string` | `false` | `""` |
| `gh_artifact_name` | <p>Name of the artifact to download. If only 'gh<em>artifact</em>path' is set, then all artifacts are downloaded. If both 'gh<em>artifact</em>path' and 'gh<em>artifact</em>name' are unset, artifacts are not downloaded.</p> | `string` | `false` | `""` |
| `gh_checkout_ref` | <p>The branch, tag or SHA to checkout.</p> | `string` | `false` | `""` |
| `gh_artifact_pattern` | <p>A glob pattern to the artifacts that should be downloaded. Ignored if name is specified.</p> | `string` | `false` | `""` |
| `gh_artifact_merge_multiple` | <p>When multiple artifacts are matched, this changes the behavior of the destination directories. If true, the downloaded artifacts will be in the same directory specified by path. If false, the downloaded artifacts will be extracted into individual named directories within the specified path. Optional. Default is 'false'.</p> | `boolean` | `false` | `""` |
| `gh_comment` | <p>Whether to post a comment on the PR with the Terraform plan</p> | `string` | `false` | `changes-only` |
| `tf_dir` | <p>Path to the Terraform root module to apply.</p> | `string` | `false` | `""` |
| `tf_backend_configs` | <p>List of Terraform backend config values, one per line.</p> | `string` | `false` | `""` |
Expand Down Expand Up @@ -100,6 +102,20 @@ jobs:
# Required: false
# Default: ""

gh_artifact_pattern:
# A glob pattern to the artifacts that should be downloaded. Ignored if name is specified.
#
# Type: string
# Required: false
# Default: ""

gh_artifact_merge_multiple:
# When multiple artifacts are matched, this changes the behavior of the destination directories. If true, the downloaded artifacts will be in the same directory specified by path. If false, the downloaded artifacts will be extracted into individual named directories within the specified path. Optional. Default is 'false'.
#
# Type: boolean
# Required: false
# Default: ""

gh_comment:
# Whether to post a comment on the PR with the Terraform plan
#
Expand Down

0 comments on commit 5fb7e98

Please sign in to comment.