Skip to content

Commit dd189be

Browse files
committed
test
1 parent a4d0561 commit dd189be

File tree

3 files changed

+190
-38
lines changed

3 files changed

+190
-38
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Code Deployment
2+
run-name: ${{ github.event_name == 'workflow_dispatch' && format('Manual deployment of {0} to {1}', github.ref_name, inputs.environment) || null }}
3+
on:
4+
push:
5+
branches:
6+
- dev
7+
- qa
8+
- prod
9+
- release/*
10+
- feature/*
11+
- 'dev/[1-4]'
12+
- hotfix/1
13+
workflow_dispatch:
14+
inputs:
15+
environment:
16+
description: 'Environment to deploy to.'
17+
default: dev
18+
19+
permissions:
20+
id-token: write
21+
contents: write
22+
jobs:
23+
environment:
24+
name: Environment
25+
uses: ./.github/workflows/environment.yml
26+
test:
27+
name: Test
28+
needs: environment
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Checkout
32+
run: |
33+
echo "Environment: ${{ needs.environment.outputs.environment }}"
34+
echo "Environment Capitalize Underscore: ${{ needs.environment.outputs.environment-capitalize-underscore }}"
35+
echo "Environment ECR Policy Prefix: ${{ needs.environment.outputs.environment-ecr-policy-prefix }}"
36+
echo "Vault ID: ${{ needs.environment.outputs.vaultID }}"
37+
echo "Push Event: ${{ needs.environment.outputs.push-event }}"
38+
echo "Manual Event: ${{ needs.environment.outputs.manual-event }}"

.github/workflows/environment.yml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
vaultID:
5+
type: string
6+
description: 'ID of the vault secret, only necessary if your vault secret differs from the job number in the repo name.'
7+
default: ''
8+
environment_override:
9+
type: string
10+
description: 'Override the environment detection logic and explicitly set the environment'
11+
required: false
12+
default: ''
13+
outputs:
14+
environment:
15+
description: "The name of the environment to use. Value is based off the branch name or based on the 'Environment' input variable from the manual action."
16+
value: ${{ jobs.environment.outputs.environment }}
17+
environment-capitalize-underscore:
18+
description: "The same value as the 'environment' output but capitalized and with dashes replaced with underscores."
19+
value: ${{ jobs.environment.outputs.environment-capitalize-underscore}}
20+
environment-ecr-policy-prefix:
21+
description: 'The ECR policy prefix for the given environment/repo.'
22+
value: ${{ jobs.environment.outputs.environment-ecr-policy-prefix }}
23+
vaultID:
24+
description: 'The Vault ID for the given environment/repo. Will be in the format of 1234-1.'
25+
value: ${{ jobs.environment.outputs.vaultID }}
26+
push-event:
27+
description: 'A code push trigger.'
28+
value: ${{ jobs.environment.outputs.push-event }}
29+
manual-event:
30+
description: 'A manual trigger.'
31+
value: ${{ jobs.environment.outputs.manual-event }}
32+
jobs:
33+
environment:
34+
runs-on: ubuntu-latest
35+
name: Determine Environment
36+
outputs:
37+
environment: ${{ steps.environment.outputs.environment }}
38+
environment-capitalize-underscore: ${{ steps.environment.outputs.environment-capitalize-underscore }}
39+
environment-ecr-policy-prefix: ${{ steps.environment.outputs.environment-ecr-policy-prefix }}
40+
vaultID: ${{ steps.vaultID.outputs.vaultID }}
41+
push-event: ${{ steps.environment.outputs.push-event }}
42+
manual-event: ${{ steps.environment.outputs.manual-event }}
43+
steps:
44+
- name: Get VaultID
45+
id: vaultID
46+
run: |
47+
if [ -z "${{ inputs.vaultID }}" ]
48+
then
49+
VAULT_ID=$(echo ${{ github.repository }} | grep -oE '[0-9]+-[0-9]+')
50+
else
51+
VAULT_ID=${{ inputs.vaultID }}
52+
fi
53+
echo "vaultID=$VAULT_ID" >> $GITHUB_OUTPUT
54+
- name: Get Branch Name
55+
id: branchName
56+
uses: tj-actions/branch-names@v8
57+
- name: Set Environment Based On Branch, input variable, or override
58+
id: environment
59+
run: |
60+
PUSH_EVENT=false
61+
MANUAL_EVENT=false
62+
63+
echo "INPUTS: ${{ toJson(inputs) }}"
64+
echo "GITHUB: ${{ toJson(github) }}"
65+
66+
# Check for environment override first
67+
if [ ! -z "${{ inputs.environment_override }}" ]
68+
then
69+
ENVIRONMENT="${{ inputs.environment_override }}"
70+
MANUAL_EVENT=true
71+
elif [ ${{ github.event_name}} == "push" ]
72+
then
73+
if [[ ${{ steps.branchName.outputs.current_branch }} =~ ^feature/patch-.*$ ]]; then
74+
ENVIRONMENT="dev"
75+
elif [[ ${{ steps.branchName.outputs.current_branch }} =~ ^release/patch-.*$ ]]; then
76+
ENVIRONMENT="qa"
77+
elif [[ ${{ steps.branchName.outputs.current_branch }} == "master" ]]; then
78+
ENVIRONMENT="prod"
79+
elif [[ ${{ steps.branchName.outputs.current_branch }} == "release-next" ]]; then
80+
ENVIRONMENT="stage"
81+
else
82+
ENVIRONMENT=$(echo ${{ steps.branchName.outputs.current_branch }} | sed 's/feature\//dev-/g' | sed 's/release\//qa-/g' | sed 's/dev\//dev-/g' | sed 's/hotfix\//hotfix-/g')
83+
fi
84+
PUSH_EVENT=true
85+
else
86+
ENVIRONMENT=${{ inputs.environment }}
87+
MANUAL_EVENT=true
88+
fi
89+
echo "environment=$ENVIRONMENT" >> $GITHUB_OUTPUT
90+
91+
MODIFIED_ENV=$(echo "$ENVIRONMENT" | tr '-' '_' | tr '[:lower:]' '[:upper:]')
92+
echo "environment-capitalize-underscore=$MODIFIED_ENV" >> $GITHUB_OUTPUT
93+
94+
# Define the associative array for special ECR policy prefixes
95+
declare -A ECR_POLICY_PREFIXES=(
96+
["dev"]="dev-main"
97+
["qa"]="qa-main"
98+
)
99+
100+
# Determine the ECR policy prefix
101+
if [[ -v ECR_POLICY_PREFIXES[$ENVIRONMENT] ]]; then
102+
ECR_POLICY_PREFIX="${ECR_POLICY_PREFIXES[$ENVIRONMENT]}"
103+
else
104+
ECR_POLICY_PREFIX="$ENVIRONMENT"
105+
fi
106+
echo "environment-ecr-policy-prefix=$ECR_POLICY_PREFIX" >> $GITHUB_OUTPUT
107+
108+
echo "push-event=$PUSH_EVENT" >> $GITHUB_OUTPUT
109+
echo "manual-event=$MANUAL_EVENT" >> $GITHUB_OUTPUT
110+
111+
echo "## Environment Summary
112+
| Environment | ECR Policy Prefix | Push Event | Manual Event | Vault ID |
113+
| ------------ | ----------------- | ----------- | ------------- | --------- |
114+
| $ENVIRONMENT | $ECR_POLICY_PREFIX | $PUSH_EVENT | $MANUAL_EVENT | ${{ steps.vaultID.outputs.vaultID }} |" >> $GITHUB_STEP_SUMMARY

.github/workflows/release.yml

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
name: Release
1+
# name: Release
22

3-
on:
4-
push:
5-
branches:
6-
- master
7-
jobs:
8-
publish-gpr:
9-
name: Publish Actions
10-
runs-on: ubuntu-latest
11-
steps:
12-
- uses: actions/checkout@v2
13-
with:
14-
fetch-depth: 0
15-
- name: Get changed files
16-
id: changed-files
17-
uses: tj-actions/changed-files@v43
18-
with:
19-
json: 'true'
3+
# on:
4+
# push:
5+
# branches:
6+
# - master
7+
# jobs:
8+
# publish-gpr:
9+
# name: Publish Actions
10+
# runs-on: ubuntu-latest
11+
# steps:
12+
# - uses: actions/checkout@v2
13+
# with:
14+
# fetch-depth: 0
15+
# - name: Get changed files
16+
# id: changed-files
17+
# uses: tj-actions/changed-files@v43
18+
# with:
19+
# json: 'true'
2020

21-
# You can add more steps that use the output from changed-files here.
22-
# Example: Print names of changed files
23-
- name: Print changed files
24-
run: |
25-
echo "Changed files: ${{ steps.changed-files.outputs.all_changed_and_modified_files }}"
26-
shell: bash
27-
- uses: actions/setup-node@v1
28-
with:
29-
node-version: 20
30-
- name: Bump versions and publish packages
31-
run: |
32-
npm install
33-
npx lerna exec npm run package
34-
git config user.name "Lerna Bot"
35-
git config user.email "LernaBot@24g.com"
36-
git add packages/*/dist/ --force
37-
git commit -m "chore: Update dist" || echo "No changes to commit"
38-
npx lerna version --conventional-commits --create-release github --yes
39-
env:
40-
GH_TOKEN: ${{ secrets.SEMANTIC_PAT }}
21+
# # You can add more steps that use the output from changed-files here.
22+
# # Example: Print names of changed files
23+
# - name: Print changed files
24+
# run: |
25+
# echo "Changed files: ${{ steps.changed-files.outputs.all_changed_and_modified_files }}"
26+
# shell: bash
27+
# - uses: actions/setup-node@v1
28+
# with:
29+
# node-version: 20
30+
# - name: Bump versions and publish packages
31+
# run: |
32+
# npm install
33+
# npx lerna exec npm run package
34+
# git config user.name "Lerna Bot"
35+
# git config user.email "LernaBot@24g.com"
36+
# git add packages/*/dist/ --force
37+
# git commit -m "chore: Update dist" || echo "No changes to commit"
38+
# npx lerna version --conventional-commits --create-release github --yes
39+
# env:
40+
# GH_TOKEN: ${{ secrets.SEMANTIC_PAT }}

0 commit comments

Comments
 (0)