Skip to content

Commit

Permalink
init()
Browse files Browse the repository at this point in the history
  • Loading branch information
hsupu committed Feb 10, 2022
0 parents commit beaae6c
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Test

on:
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push
push:
branches:
- 'main'

# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch
workflow_dispatch:
inputs:
install-dir:
required: false
type: string
default: '/usr/local/aws-cli'
bin-dir:
required: false
type: string
default: '/usr/local/bin'
gpg-verify:
required: false
type: boolean
default: true

jobs:
try:
name: try
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2

- name: setup aws-cli
uses: ./
with:
install-dir: ${{ github.event.inputs.install-dir }}
bin-dir: ${{ github.event.inputs.bin-dir }}
gpg-verify: ${{ github.event.inputs.gpg-verify }}
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# setup-awscli

A GitHub Action to set up aws-cli v2 **in linux job**.

The action follows instructions in https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html

You can directly copy the steps from `action.yml` to your job.

Usage:

```yaml
- name: setup awscli
uses: hsupu@setup-awscli@v1
with:
# these are default values
install-dir: /usr/local/aws-cli
bin-dir: /usr/local/bin

- name: s3 put-object
# https://docs.aws.amazon.com/cli/latest/reference/s3api/put-object.html#examples
run: |
echo Hello World > a.txt
aws s3api put-object --bucket <bucket> --key <key> --body a.txt
env:
# https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: 'us-east-1'
```
Notice: add action secrets: `AWS_ACCESS_KEY_ID` `AWS_SECRET_ACCESS_KEY`.

You can also find AWS official-released GitHub Actions in https://github.com/aws-actions .
114 changes: 114 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# https://docs.github.com/en/actions/creating-actions/about-custom-actions
# https://docs.github.com/en/actions/creating-actions/creating-a-composite-action
#
name: 'setup-awscli'
description: 'Set up aws-cli v2 in linux job'

inputs:
install-dir:
required: false
default: '/usr/local/aws-cli'
bin-dir:
required: false
default: '/usr/local/bin'
gpg-verify:
required: true
default: true

outputs: {}

runs:
using: 'composite'
steps:
- name: download zip.sig
shell: bash
run: |
curl -o awscliv2.zip.sig https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip.sig
- name: setup cache
id: cache-sig
uses: actions/cache@v2
with:
path: awscliv2.zip
key: ${{ runner.os }}-${{ hashFiles('awscliv2.zip.sig') }}

- name: download zip
if: ${{ steps.cache-sig.outputs.cache-hit != 'true' }}
shell: bash
run: |
curl -o awscliv2.zip https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip
- name: gpg import
if: ${{ inputs.gpg-verify == 'true' }}
shell: bash
run: |
cat > aws-gpg-public-key.txt <<- __EOF__
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBF2Cr7UBEADJZHcgusOJl7ENSyumXh85z0TRV0xJorM2B/JL0kHOyigQluUG
ZMLhENaG0bYatdrKP+3H91lvK050pXwnO/R7fB/FSTouki4ciIx5OuLlnJZIxSzx
PqGl0mkxImLNbGWoi6Lto0LYxqHN2iQtzlwTVmq9733zd3XfcXrZ3+LblHAgEt5G
TfNxEKJ8soPLyWmwDH6HWCnjZ/aIQRBTIQ05uVeEoYxSh6wOai7ss/KveoSNBbYz
gbdzoqI2Y8cgH2nbfgp3DSasaLZEdCSsIsK1u05CinE7k2qZ7KgKAUIcT/cR/grk
C6VwsnDU0OUCideXcQ8WeHutqvgZH1JgKDbznoIzeQHJD238GEu+eKhRHcz8/jeG
94zkcgJOz3KbZGYMiTh277Fvj9zzvZsbMBCed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sBJr+opwJw/Zio2LMjQBOqlm3K1A4zFTh7wBC7He6KPQea1p2XAMgtvATtNe
YLZATHZKTJyiqA==
=vYOk
-----END PGP PUBLIC KEY BLOCK-----
__EOF__
gpg --import aws-gpg-public-key.txt
rm aws-gpg-public-key.txt
- name: gpg verify
if: ${{ inputs.gpg-verify == 'true' }}
shell: bash
run: |
gpg --verify awscliv2.zip.sig awscliv2.zip
- name: unzip
shell: bash
run: |
unzip -q awscliv2.zip
- name: install
shell: bash
run: |
EXPR="sudo ./aws/install"
if [[ -e $(which aws) ]]; then
realpath -L $(which aws)
echo update existing aws-cli
EXPR="$EXPR --update"
fi
INSTALL_DIR=${{ inputs.install-dir }}
[[ -n $INSTALL_DIR ]] && EXPR="$EXPR -i ${INSTALL_DIR}"
BIN_DIR=${{ inputs.bin-dir }}
[[ -n $BIN_DIR ]] && EXPR="$EXPR -b ${BIN_DIR}"
eval $EXPR
- name: aws --version
shell: bash
run: |
realpath -L $(which aws)
aws --version

0 comments on commit beaae6c

Please sign in to comment.