Skip to content

Commit

Permalink
feat(s3-head-object-action): ZEUS-XXXX add initial action
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhrytsyna committed Mar 6, 2023
1 parent 4e4e31b commit dfdfcce
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 2 deletions.
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM python:3.8-alpine

LABEL "com.github.actions.name"="S3 Head Object"
LABEL "com.github.actions.description"="Head object in AWS S3"
LABEL "com.github.actions.icon"="refresh-cw"
LABEL "com.github.actions.color"="green"

ENV AWSCLI_VERSION='1.18.14'

RUN apk add jq
RUN pip install --quiet --no-cache-dir awscli==${AWSCLI_VERSION}

ADD entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
46 changes: 44 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,44 @@
# s3-head-object-action
S3 Head Object action
# GitHub Action to Head object in S3 Bucket 🔄

This simple action uses the [vanilla AWS CLI](https://docs.aws.amazon.com/cli/index.html) to head object in remote S3 bucket.


## Usage

### `workflow.yml` Example

```yaml
name: Head Object

on:
push:
branches:
- master

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: StreamAMG/s3-head-object-action@master
env:
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_S3_OBJECT_KEY: 'file.json'
AWS_REGION: 'eu-west-1' # optional: defaults to eu-west-1
```
### Configuration
The following settings must be passed as environment variables as shown in the example. Sensitive information, especially `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`, should be [set as encrypted secrets](https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables) — otherwise, they'll be public to anyone browsing your repository's source code and CI logs.

| Key | Value | Suggested Type | Required | Default |
| ------------- | ------------- | ------------- | ------------- | ------------- |
| `AWS_ACCESS_KEY_ID` | Your AWS Access Key. [More info here.](https://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html) | `secret env` | **Yes** | N/A |
| `AWS_SECRET_ACCESS_KEY` | Your AWS Secret Access Key. [More info here.](https://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html) | `secret env` | **Yes** | N/A |
| `AWS_S3_BUCKET` | The name of the bucket you're syncing to. For example, `my-app-releases`. | `secret env` | **Yes** | N/A |
| `AWS_S3_OBJECT_KEY` | The key of the object in bucket you want to run `s3api head-object` CLI command. For example, `file.json` or `my-app-releases`. | `env` | **Yes** | N/A |
| `AWS_REGION` | The region where you created your bucket. Set to `us-east-1` by default. [Full list of regions here.](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-available-regions) | `env` | No | `eu-west-1` |

9 changes: 9 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: "S3 Head object"
description: "Head object in AWS S3"
author: streamamg
runs:
using: docker
image: Dockerfile
branding:
icon: refresh-cw
color: green
45 changes: 45 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/sh

set -e

if [ -z "$AWS_ACCESS_KEY_ID" ]; then
echo "AWS_ACCESS_KEY_ID is not set. Quitting."
exit 1
fi

if [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
echo "AWS_SECRET_ACCESS_KEY is not set. Quitting."
exit 1
fi

if [ -z "$AWS_REGION" ]; then
AWS_REGION="eu-west-1"
fi


if [ -z "$AWS_S3_BUCKET" ]; then
echo "AWS_S3_BUCKET is not set. Quitting."
exit 1
fi

if [ -z "$AWS_S3_OBJECT_KEY" ]; then
echo "AWS_S3_OBJECT_KEY is not set. Quitting."
exit 1
fi

aws configure --profile s3-head-object-action <<-EOF > /dev/null 2>&1
${AWS_ACCESS_KEY_ID}
${AWS_SECRET_ACCESS_KEY}
${AWS_REGION}
json
EOF

echo s3_object=$(aws s3api head-object --bucket ${AWS_S3_BUCKET} --key ${AWS_S3_OBJECT_KEY} \
--profile s3-head-object-action | jq "@json") >> $GITHUB_OUTPUT

aws configure --profile s3-head-object-action <<-EOF > /dev/null 2>&1
null
null
null
text
EOF

0 comments on commit dfdfcce

Please sign in to comment.