-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
72 lines (60 loc) · 2.57 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
name: Login Amazon ECR and Setup ECR Private Repository
description: Logs into Amazon ECR and create a repository if it doesn't exist.
branding:
icon: cloud
color: orange
inputs:
RepositoryName:
description: The name to use for the private repository.
required: true
ImageTagMutability:
description: The tag mutability setting for the repository. This input is always applied.
required: false
AwsRegion:
description: AWS Region, e.g. us-east-2
required: false
RegistryId:
description: Repository's Registry ID (AWS Account ID)
required: false
runs:
using: composite
steps:
- shell: bash
run: aws sts get-caller-identity >/dev/null
- shell: bash
id: aws
run: |
if [ -z "${{ inputs.AwsRegion }}" ]; then
REGION=$AWS_REGION
else
REGION=${{ inputs.AwsRegion }}
fi
echo "region=$REGION" >> "$GITHUB_OUTPUT"
if [ -z "${{ inputs.RegistryId }}" ]; then
REGISTRY_ID=$(aws sts get-caller-identity --query Account --output text)
else
REGISTRY_ID=${{ inputs.RegistryId }}
fi
echo "registry_id=$REGISTRY_ID" >> "$GITHUB_OUTPUT"
- shell: bash
id: repository
run: |
if aws ecr describe-repositories --repository-name ${{ inputs.RepositoryName }} --region ${{ steps.aws.outputs.region }} --registry-id ${{ steps.aws.outputs.registry_id }} >/dev/null 2>&1; then
exit 0
fi
aws ecr create-repository --repository-name ${{ inputs.RepositoryName }} --region ${{ steps.aws.outputs.region }} --registry-id ${{ steps.aws.outputs.registry_id }} >/dev/null
- shell: bash
run: |
TagMutability="${{ inputs.ImageTagMutability }}"
if [[ -z "$TagMutability" ]]; then
exit 0
fi
if [[ "$TagMutability" != "MUTABLE" && "$TagMutability" != "IMMUTABLE" ]]; then
echo "::error title=Invalid Input::ImageTagMutability Input must be either MUTABLE or IMMUTABLE."
exit 1
fi
CURRENT_SETTING=$(aws ecr describe-repositories --repository-names ${{ inputs.RepositoryName }} --region ${{ steps.aws.outputs.region }} --registry-id ${{ steps.aws.outputs.registry_id }} --query 'repositories[0].imageTagMutability' --output text)
if [ "$CURRENT_SETTING" == "$TagMutability" ]; then
exit 0
fi
aws ecr put-image-tag-mutability --repository-name ${{ inputs.RepositoryName }} --image-tag-mutability $TagMutability --region ${{ steps.aws.outputs.region }} --registry-id ${{ steps.aws.outputs.registry_id }} >/dev/null