Skip to content

Commit 943f6e0

Browse files
authored
Add setup AWS CA action (#64)
1 parent 1ccc86d commit 943f6e0

File tree

3 files changed

+155
-0
lines changed

3 files changed

+155
-0
lines changed

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Available actions are:
1919
14. [update_airflow_variables](#update_airflow_variables)
2020
15. [contribute_changes](#contribute_changes)
2121
16. [activate_workflow](#activate_workflow)
22+
16. [setup_aws_ca](#setup_aws_ca)
2223

2324
## semver_release
2425

@@ -801,3 +802,54 @@ jobs:
801802
project_name: ${{ env.PROJECT_NAME }}
802803
id: read
803804
```
805+
806+
## setup_aws_ca
807+
808+
Setup AWS CodeArtifact credentials
809+
810+
### Inputs
811+
| Name | Description | Optional | Default Value |
812+
|---------------------|:-------------------------------------------------|----------|---------------|
813+
| aws_access_key | AWS access key | False | |
814+
| aws_access_key_id | AWS access key ID | False | |
815+
| mode | Setup for read or publish | False | |
816+
| aws_ca_domain | AWS CodeArtifact domain | False | |
817+
| aws_ca_domain_owner | AWS CodeArtifact domain owner name | False | |
818+
| aws_ca_repository | AWS CodeArtifact repository name | False | |
819+
| aws_region | AWS region where the artifact storage is located | True | eu-central-1 |
820+
821+
### Outputs
822+
| Name | Description |
823+
|-------|:------------------------------------------------------|
824+
| url | Python artifact storage URL (pip or twine-compatible) |
825+
| user | User Name |
826+
| token | Access token |
827+
828+
### Usage
829+
```yaml
830+
name: Deploy latest tag
831+
832+
on:
833+
workflow_dispatch:
834+
835+
jobs:
836+
create_release:
837+
runs-on: ubuntu-latest
838+
steps:
839+
- name: Setup AWS CA
840+
uses: SneaksAndData/github-actions/setup_aws_ca@v0.1.1
841+
with:
842+
aws_access_key: ${{ env.AWS_ACCESS_KEY }}
843+
aws_access_key_id: ${{ env.AWS_ACCESS_KEY_ID }}
844+
mode: read
845+
aws_ca_domain: some-domain
846+
aws_ca_domain_owner: some-domain-owner
847+
aws_ca_repository: some-repository
848+
id: aws_ca
849+
- name: Install Poetry and dependencies
850+
uses: SneaksAndData/github-actions/install_poetry@v0.1.0
851+
with:
852+
pypi_repo_url: ${{ steps.aws_ca.outputs.url }}
853+
pypi_token_username: ${{ steps.aws_ca.outputs.user }}
854+
pypi_token: ${{ steps.aws_ca.outputs.token }}
855+
```

setup_aws_ca/action.yaml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Setup AWS CA
2+
description: Setup AWS Code Artifacts credentials
3+
4+
branding:
5+
icon: 'tag'
6+
color: 'green'
7+
8+
inputs:
9+
aws_access_key:
10+
description: AWS access key
11+
required: true
12+
13+
aws_access_key_id:
14+
description: AWS access key id
15+
required: true
16+
17+
mode:
18+
description: Setup for read or publish
19+
required: true
20+
21+
aws_ca_domain:
22+
description: AWS CodeArtifact domain
23+
required: true
24+
25+
aws_ca_domain_owner:
26+
description: AWS CodeArtifact domain owner name
27+
required: true
28+
29+
aws_ca_repository:
30+
description: AWS CodeArtifact repository name
31+
required: true
32+
33+
aws_region:
34+
description: AWS region where the artifact storage is located
35+
required: false
36+
default: eu-central-1
37+
38+
39+
outputs:
40+
url:
41+
description: AWS CodeArtifact URl
42+
value: ${{ steps.aws_ca.outputs.url }}
43+
user:
44+
description: AWS CodeArtifact username
45+
value: ${{ steps.aws_ca.outputs.user }}
46+
token:
47+
description: AWS CodeArtifact access token
48+
value: ${{ steps.aws_ca.outputs.token }}
49+
50+
runs:
51+
using: "composite"
52+
steps:
53+
- name: Configure AWS Credentials
54+
uses: aws-actions/configure-aws-credentials@v3
55+
with:
56+
aws-secret-access-key: ${{ inputs.aws_access_key }}
57+
aws-access-key-id: ${{ inputs.aws_access_key_id }}
58+
aws-region: ${{ inputs.aws_region }}
59+
- run: $GITHUB_ACTION_PATH/setup_aws_ca.sh
60+
id: aws_ca
61+
env:
62+
MODE: ${{ inputs.mode }}
63+
AWS_CA_DOMAIN: ${{ inputs.aws_ca_domain }}
64+
AWS_CA_DOMAIN_OWNER: ${{ inputs.aws_ca_domain_owner }}
65+
AWS_REGION: ${{ inputs.aws_region }}
66+
shell: bash

setup_aws_ca/setup_aws_ca.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright (c) 2022 Ecco Sneaks & Data
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -Eeuo pipefail
18+
19+
token="$(aws codeartifact get-authorization-token --domain "$AWS_CA_DOMAIN" --domain-owner "$AWS_CA_DOMAIN_OWNER" --region "$AWS_REGION" --query authorizationToken --output text)"
20+
echo "::add-mask::$token"
21+
echo "token=$token" >> "$GITHUB_OUTPUT"
22+
23+
if [[ "$MODE" == "read" ]]
24+
then
25+
url="$(aws codeartifact get-repository-endpoint --domain "$AWS_CA_DOMAIN" --domain-owner "$AWS_CA_DOMAIN_OWNER" --repository "$AWS_CA_REPOSITORY" --region "$AWS_REGION" --format pypi --query repositoryEndpoint --output text)/simple/"
26+
elif [[ "$MODE" == "publish" ]]
27+
then
28+
url="$(aws codeartifact get-repository-endpoint --domain "$AWS_CA_DOMAIN" --domain-owner "$AWS_CA_DOMAIN_OWNER" --repository "$AWS_CA_REPOSITORY" --region "$AWS_REGION" --format pypi --query repositoryEndpoint --output text)"
29+
else
30+
>&2 echo "Unknown mode: $MODE"
31+
exit 1
32+
fi;
33+
34+
echo "::add-mask::$url"
35+
echo "url=$url" >> "$GITHUB_OUTPUT"
36+
37+
echo "user=aws" >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)