Skip to content

Commit 75516f9

Browse files
committed
Initial release: deployment environment resolver action
0 parents  commit 75516f9

5 files changed

Lines changed: 773 additions & 0 deletions

File tree

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 code4mk
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
# Deployment Environment Resolver
2+
3+
A reusable GitHub Action that resolves deployment environments from workflow inputs, branch/ref mappings, or tag patterns — with wildcard support.
4+
5+
Replace inline shell scripts in your workflows with a single, configurable action step.
6+
7+
## Features
8+
9+
- **Input mapping** — resolve from `workflow_dispatch` inputs
10+
- **Branch mapping** — map branches to environments with glob/wildcard support
11+
- **Tag mapping** — map tag patterns to environments (e.g. `v*` → prod)
12+
- **Default fallback** — configurable fallback environment
13+
- **Strict mode** — fail if no mapping matches
14+
- **Debug mode** — verbose logging for troubleshooting
15+
- **Match source output** — know _how_ the environment was resolved
16+
17+
## Quick Start
18+
19+
```yaml
20+
- name: Resolve environment
21+
id: env
22+
uses: code4mk/deployment-env-resolver-action@v1
23+
24+
- name: Deploy
25+
run: echo "Deploying to ${{ steps.env.outputs.environment }}"
26+
```
27+
28+
With zero configuration, the action defaults to `dev`.
29+
30+
## Usage
31+
32+
### Basic — Branch Mapping
33+
34+
```yaml
35+
- name: Resolve environment
36+
id: env
37+
uses: code4mk/deployment-env-resolver-action@v1
38+
with:
39+
ref-mapping: |
40+
main=prod
41+
develop=staging
42+
feature/*=preview
43+
default-env: dev
44+
```
45+
46+
### With Workflow Dispatch
47+
48+
```yaml
49+
on:
50+
workflow_dispatch:
51+
inputs:
52+
environment:
53+
type: choice
54+
options:
55+
- dev
56+
- staging
57+
- prod
58+
59+
jobs:
60+
deploy:
61+
runs-on: ubuntu-latest
62+
steps:
63+
- uses: actions/checkout@v4
64+
65+
- name: Resolve environment
66+
id: env
67+
uses: code4mk/deployment-env-resolver-action@v1
68+
with:
69+
input-mapping: |
70+
prod=production
71+
staging=staging
72+
dev=development
73+
ref-mapping: |
74+
main=production
75+
develop=staging
76+
default-env: development
77+
```
78+
79+
### With Tag Mapping
80+
81+
```yaml
82+
- name: Resolve environment
83+
id: env
84+
uses: code4mk/deployment-env-resolver-action@v1
85+
with:
86+
tag-mapping: |
87+
v*=prod
88+
rc-*=staging
89+
beta-*=preview
90+
ref-mapping: |
91+
main=prod
92+
develop=staging
93+
default-env: dev
94+
```
95+
96+
### Strict Mode
97+
98+
Fail the step if no mapping matches and no default is suitable:
99+
100+
```yaml
101+
- name: Resolve environment
102+
id: env
103+
uses: code4mk/deployment-env-resolver-action@v1
104+
with:
105+
ref-mapping: |
106+
main=prod
107+
develop=staging
108+
strict: "true"
109+
default-env: ""
110+
```
111+
112+
### Debug Mode
113+
114+
Enable verbose logging to see which mappings are being checked:
115+
116+
```yaml
117+
- name: Resolve environment
118+
id: env
119+
uses: code4mk/deployment-env-resolver-action@v1
120+
with:
121+
ref-mapping: |
122+
main=prod
123+
debug: "true"
124+
```
125+
126+
## Inputs
127+
128+
| Input | Required | Default | Description |
129+
|---|---|---|---|
130+
| `input-mapping` | No | — | Mapping for `workflow_dispatch` inputs (`key=value` per line) |
131+
| `ref-mapping` | No | — | Mapping for branch/ref names with wildcard support (`pattern=env` per line) |
132+
| `tag-mapping` | No | — | Mapping for tag patterns (`pattern=env` per line) |
133+
| `default-env` | No | `dev` | Fallback environment if no mapping matches |
134+
| `strict` | No | `false` | Fail the step if no mapping matches and no default is set |
135+
| `debug` | No | `false` | Enable debug logging |
136+
137+
## Outputs
138+
139+
| Output | Description |
140+
|---|---|
141+
| `environment` | Resolved environment name |
142+
| `match-source` | How the environment was resolved: `input`, `ref`, `tag`, or `default` |
143+
144+
## Resolution Order
145+
146+
The action resolves the environment in this order (first match wins):
147+
148+
1. **Input mapping** — if the event is `workflow_dispatch` and an input is provided
149+
2. **Tag mapping** — if the ref type is a tag
150+
3. **Ref mapping** — branch/ref pattern matching
151+
4. **Default** — fallback value
152+
153+
## Mapping Format
154+
155+
Each mapping is a newline-separated list of `pattern=environment` pairs:
156+
157+
```
158+
main=prod
159+
develop=staging
160+
feature/*=preview
161+
release-*=staging
162+
```
163+
164+
- Patterns support bash-style glob wildcards (`*`, `?`, `[...]`)
165+
- Lines starting with `#` are treated as comments
166+
- Empty lines are ignored
167+
- Whitespace around keys and values is trimmed
168+
169+
## Full Example Workflow
170+
171+
```yaml
172+
name: Deploy
173+
174+
on:
175+
push:
176+
branches: [main, develop, "feature/*"]
177+
tags: ["v*"]
178+
179+
workflow_dispatch:
180+
inputs:
181+
environment:
182+
type: choice
183+
description: Target environment
184+
options:
185+
- dev
186+
- staging
187+
- prod
188+
189+
jobs:
190+
deploy:
191+
runs-on: ubuntu-latest
192+
steps:
193+
- uses: actions/checkout@v4
194+
195+
- name: Resolve environment
196+
id: env
197+
uses: code4mk/deployment-env-resolver-action@v1
198+
with:
199+
input-mapping: |
200+
prod=prod
201+
staging=staging
202+
dev=dev
203+
tag-mapping: |
204+
v*=prod
205+
ref-mapping: |
206+
main=prod
207+
develop=staging
208+
feature/*=preview
209+
default-env: dev
210+
debug: "true"
211+
212+
- name: Use resolved environment
213+
run: |
214+
echo "Environment: ${{ steps.env.outputs.environment }}"
215+
echo "Matched via: ${{ steps.env.outputs.match-source }}"
216+
```
217+
218+
## License
219+
220+
[MIT](LICENSE)

action.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: "Deployment Environment Resolver"
2+
description: "Resolve deployment environment from workflow_dispatch inputs, branch/ref mapping, or tag patterns with wildcard support"
3+
author: "code4mk"
4+
5+
branding:
6+
icon: "git-branch"
7+
color: "blue"
8+
9+
inputs:
10+
input-mapping:
11+
description: "Mapping for workflow_dispatch inputs (key=value per line, e.g. prod=production)"
12+
required: false
13+
14+
ref-mapping:
15+
description: "Mapping for branch/ref names with wildcard support (pattern=env per line, e.g. main=prod)"
16+
required: false
17+
18+
tag-mapping:
19+
description: "Mapping for tag patterns (pattern=env per line, e.g. v*=prod)"
20+
required: false
21+
22+
default-env:
23+
description: "Fallback environment if no mapping matches"
24+
required: false
25+
default: "dev"
26+
27+
strict:
28+
description: "Fail the step if no mapping matches and no default is set"
29+
required: false
30+
default: "false"
31+
32+
debug:
33+
description: "Enable debug logging"
34+
required: false
35+
default: "false"
36+
37+
outputs:
38+
environment:
39+
description: "Resolved environment name"
40+
value: ${{ steps.resolve.outputs.environment }}
41+
match-source:
42+
description: "How the environment was resolved (input | ref | tag | default)"
43+
value: ${{ steps.resolve.outputs.match_source }}
44+
45+
runs:
46+
using: "composite"
47+
steps:
48+
- name: Resolve environment
49+
id: resolve
50+
shell: bash
51+
run: bash "${{ github.action_path }}/scripts/resolve-env.sh"
52+
env:
53+
EVENT_NAME: ${{ github.event_name }}
54+
REF_NAME: ${{ github.ref_name }}
55+
REF_TYPE: ${{ github.ref_type }}
56+
INPUT_ENV: ${{ github.event.inputs.environment }}
57+
INPUT_MAPPING: ${{ inputs.input-mapping }}
58+
REF_MAPPING: ${{ inputs.ref-mapping }}
59+
TAG_MAPPING: ${{ inputs.tag-mapping }}
60+
DEFAULT_ENV: ${{ inputs.default-env }}
61+
STRICT_MODE: ${{ inputs.strict }}
62+
DEBUG_MODE: ${{ inputs.debug }}

0 commit comments

Comments
 (0)