-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
110 lines (101 loc) · 4.2 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
name: InfraPatch Github Action
description: A github action to update provider and module dependencies in terraform files
author: "Noah Canadea"
inputs:
target_branch_name:
description: "Name of the branch where changes will be pushed to. Defaults to feature/infrapatch-bot"
required: true
default: "feature/infrapatch-bot"
repository_name:
description: "Name of the repository to run the action in. Defaults to the current repository"
required: false
default: ${{ github.repository }}
default_registry_domain:
description: "Default registry domain to use for modules and providers without explicit registry domain set. Defaults to registry.terraform.io"
required: false
default: "registry.terraform.io"
git_user:
description: "Git user to use for commits. Defaults to InfraPatch Bot"
required: false
default: "InfraPatch Bot"
git_email:
description: "Git email to use for commits. Defaults to [email protected]"
required: false
default: "[email protected]"
report_only:
description: "Only report new versions. Do not update files. Defaults to false"
default: "false"
required: true
enabled_providers:
description: "Comma separated list of provider names to enable. Defaults to terraform_modules,terraform_providers"
default: "terraform_modules,terraform_providers"
required: true
terraform_registry_secrets:
description: "Registry secrets to use for private terraform registries. Needs to be a newline separated list of secrets in the format <registry_domain>:<secret_name>. Defaults to empty"
required: false
default: ""
working_directory_relative:
description: "Working directory to run the action in. Defaults to the root of the repository"
required: false
github_token:
description: "GitHub access token. Defaults to github.token."
default: ${{ github.token }}
outputs:
target_branch:
description: "Name of the branch where changes will be pushed to"
value: ${{ inputs.target_branch_name }}
runs:
using: composite
steps:
- name: Extract branch name
id: branch
shell: bash
run: |
head_branch_origin="origin/${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
head_branch="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
target_branch="${{ inputs.target_branch_name }}"
target_branch_origin="origin/${{ inputs.target_branch_name }}"
echo "Using head branch $head_branch and target branch $target_branch"
echo "head=$head_branch" >> $GITHUB_OUTPUT
echo "head_origin=$head_branch_origin" >> $GITHUB_OUTPUT
echo "target=$target_branch" >> $GITHUB_OUTPUT
echo "target_origin=$target_branch_origin" >> $GITHUB_OUTPUT
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install requirements
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
working-directory: ${{ github.action_path }}
shell: bash
- name: Configure git
if: ${{ inputs.report_only }} == 'false' }}
shell: bash
run: |
git config --global user.name "${{ inputs.git_user }}"
git config --global user.email "${{ inputs.git_email }}"
- name: Run InfraPatch Action
shell: bash
working-directory: ${{ github.action_path }}
run: |
module="infrapatch.action"
arguments=()
if [ "${{ runner.debug }}" == "1" ]; then
arguments+=("--debug")
fi
python -m "$module" "${arguments[@]}"
env:
# Config from inputs
GITHUB_TOKEN: ${{ inputs.github_token }}
DEFAULT_REGISTRY_DOMAIN: ${{ inputs.DEFAULT_REGISTRY_DOMAIN }}
REPOSITORY_NAME: ${{ inputs.repository_name }}
REPORT_ONLY: ${{ inputs.report_only }}
TERRAFORM_REGISTRY_SECRET_STRING: ${{ inputs.terraform_registry_secrets }}
WORKING_DIRECTORY_RELATIVE: ${{ inputs.working_directory_relative }}
ENABLED_PROVIDERS: ${{ inputs.enabled_providers }}
REPOSITORY_ROOT: ${{ github.workspace }}
# Calculated config from other steps
HEAD_BRANCH: ${{ steps.branch.outputs.head }}
TARGET_BRANCH: ${{ steps.branch.outputs.target }}