-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deploys static assets to an s3 bucket (#4)
- Loading branch information
1 parent
2784a4a
commit e328b13
Showing
17 changed files
with
708 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
|
||
name: 'Use local actions' | ||
description: | | ||
Replaces `uses` within actions that use other actions within this repo. | ||
If we do not replace with local actions, we will end up using whatever | ||
version is tagged. Currently, we are marking all internal actions with | ||
whatever the current major version is. Though we can technically use | ||
multiple versions, we would like to avoid that. | ||
Example replacement: | ||
- uses: shopsmart/github-actions/actions/npm-setup@v1 | ||
Replaced with | ||
- uses: ./actions/npm-setup | ||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: 'Use local actions' | ||
shell: bash | ||
run: $GITHUB_ACTION_PATH/use-local-actions.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env bash | ||
|
||
function use-local-actions() { | ||
set -eo pipefail | ||
|
||
for file in actions/*/action.yml; do | ||
echo "[DEBUG] Setting internal actions to local references for $file" >&2 | ||
sed -i.bak \ | ||
's/uses: shopsmart\/github-actions\/actions\/\(.*\)@.*/uses: .\/actions\/\1/g' \ | ||
"$file" | ||
done | ||
} | ||
|
||
if [ "${BASH_SOURCE[0]}" = "$0" ]; then | ||
set -u | ||
|
||
use-local-actions "${@:-}" | ||
exit $? | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
### | ||
# This test of the action is very limited. If anything, this tests | ||
# that the action is not invalid; however, it does not test any of | ||
# the functionality of downloading release assets or uploading to s3 | ||
# bucket without aws credentials. | ||
## | ||
--- | ||
|
||
name: 'Run deploy-static-assets action' | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- actions/deploy-static-assets/* | ||
- actions/unpack-archive/* | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
jobs: | ||
test-deploy-static-assets-action: | ||
name: 'Uses the deploy-static-assets action' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: 'Checkout actions' | ||
uses: actions/checkout@v2 | ||
|
||
- name: 'Use local actions' | ||
uses: ./.github/actions/use-local-actions | ||
|
||
- name: 'Create dummy files' | ||
run: | | ||
mkdir -p static-assets | ||
echo "<html><head></head><body>Hello world</body></html>" > static-assets/index.html | ||
echo "head p { color: black; }" > static-assets/style.css | ||
tar -zcvf static-assets.tgz -C static-assets/ . | ||
rm -rf static-assets/ | ||
- name: 'Run deploy static assets' | ||
uses: ./actions/deploy-static-assets | ||
with: | ||
pattern: 'static-assets.tgz' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
### | ||
# This test of the action is very limited. If anything, this tests | ||
# that the action is not invalid; however, it does not test any of | ||
# the functionality of downloading release assets or uploading to s3 | ||
# bucket without aws credentials. | ||
## | ||
--- | ||
|
||
name: 'Run unpack-archive action' | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- actions/unpack-archive/* | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
jobs: | ||
test-unpack-archive-action: | ||
name: 'Uses the unpack-archive action' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: 'Checkout actions' | ||
uses: actions/checkout@v2 | ||
|
||
- name: 'Create dummy files' | ||
run: | | ||
mkdir -p static-assets | ||
echo "<html><head></head><body>Hello world</body></html>" > static-assets/index.html | ||
echo "head p { color: black; }" > static-assets/style.css | ||
tar -zcvf static-assets.tgz -C static-assets/ . | ||
rm -rf static-assets/ | ||
- name: 'Run unpack archive' | ||
uses: ./actions/unpack-archive | ||
with: | ||
filename: 'static-assets.tgz' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,13 +16,12 @@ jobs: | |
name: 'Pre-commit check' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- | ||
name: 'Checkout' | ||
- name: 'Checkout' | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- | ||
name: 'Run pre-commit' | ||
|
||
- name: 'Run pre-commit' | ||
uses: pre-commit/[email protected] | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
|
@@ -31,12 +30,11 @@ jobs: | |
name: 'Run tests' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- | ||
name: 'Checkout' | ||
- name: 'Checkout' | ||
uses: actions/checkout@v2 | ||
- | ||
name: 'Install bats' | ||
|
||
- name: 'Install bats' | ||
run: brew install bats-core | ||
- | ||
name: 'Run action tests' | ||
|
||
- name: 'Run action tests' | ||
run: bats -r actions/*/*.bats |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
--- | ||
|
||
name: 'Deploy static assets' | ||
description: 'Deploys static assets to an s3 bucket (currently the only supported option)' | ||
|
||
inputs: | ||
pattern: | ||
description: | | ||
If downloading release assets from github, the pattern for the assets file. | ||
Otherwise, the path to the static assets. If it is an archive, it will unpacked. | ||
required: true | ||
|
||
# GH release Options | ||
github-token: | ||
description: 'The github token to allow for searching for release assets' | ||
type: string | ||
default: ${{ github.token }} | ||
tag: | ||
description: 'The github release tag to pull that assets from' | ||
default: '' | ||
|
||
# AWS (S3) Options | ||
aws-access-key-id: | ||
description: 'The AWS access key id to log into ECR with' | ||
default: '' | ||
aws-secret-access-key: | ||
description: 'The AWS secret access key to log into ECR with' | ||
default: '' | ||
aws-region: | ||
description: 'The AWS region to log into if using ECR' | ||
default: 'us-east-1' | ||
role-to-assume: | ||
description: 'Allows one to configure the assume role' | ||
default: '' | ||
role-duration-seconds: | ||
description: 'Allows one to configure the duration of assume role' | ||
default: 1200 | ||
|
||
s3-bucket: | ||
description: 'The name of the s3 bucket to upload the assets to' | ||
default: '' | ||
s3-bucket-path: | ||
description: 'The path within the s3 bucket to upload the assets to' | ||
default: '' | ||
s3-tags: | ||
description: | | ||
Key value pairs to attach to each s3 object. | ||
Example: | ||
s3-tags: | | ||
version=v1 | ||
owner=carl | ||
default: '' | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: 'Get info' | ||
id: info | ||
env: | ||
TAG: ${{ inputs.tag }} | ||
AWS_ACCESS_KEY_ID: ${{ inputs.aws-access-key-id }} | ||
AWS_SECRET_ACCESS_KEY: ${{ inputs.aws-secret-access-key }} | ||
shell: bash | ||
run: ${{ github.action_path }}/static-assets-info.sh "${{ inputs.pattern }}" | ||
|
||
- name: 'Install gh cli' | ||
shell: bash | ||
run: brew install gh | ||
# Only if we are downloading assets from gh release | ||
if: inputs.tag != '' | ||
|
||
- name: 'Download static assets' | ||
shell: bash | ||
run: gh -R "${{ github.repository }}" release download -p "${{ inputs.pattern }}" "${{ inputs.tag }}" | ||
env: | ||
GITHUB_TOKEN: ${{ inputs.github-token }} | ||
# Only if we are downloading assets from gh release | ||
if: inputs.tag != '' | ||
|
||
- name: 'Unpack release assets' | ||
id: unpack | ||
uses: shopsmart/github-actions/actions/unpack-archive@v1 | ||
with: | ||
filename: ${{ inputs.pattern }} | ||
destination: static-assets | ||
|
||
- name: 'Configure AWS credentials' | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ inputs.aws-access-key-id }} | ||
aws-secret-access-key: ${{ inputs.aws-secret-access-key }} | ||
aws-region: ${{ inputs.aws-region }} | ||
role-to-assume: ${{ inputs.role-to-assume }} | ||
role-duration-seconds: ${{ inputs.role-duration-seconds }} | ||
# Only if we are using AWS S3 | ||
if: steps.info.outputs.configure-aws-credentials == 'true' | ||
|
||
- name: 'Upload static assets' | ||
shell: bash | ||
run: $GITHUB_ACTION_PATH/upload-static-assets.sh "${{ steps.unpack.outputs.destination }}" | ||
env: | ||
S3_BUCKET: ${{ inputs.s3-bucket }} | ||
S3_BUCKET_PATH: ${{ inputs.s3-bucket-path }} | ||
# Only if we are using AWS S3 | ||
if: steps.info.outputs.configure-aws-credentials == 'true' | ||
|
||
- name: 'Tag static assets' | ||
shell: bash | ||
run: $GITHUB_ACTION_PATH/tag-static-assets.sh "${{ steps.unpack.outputs.destination }}" | ||
env: | ||
S3_BUCKET: ${{ inputs.s3-bucket }} | ||
S3_BUCKET_PATH: ${{ inputs.s3-bucket-path }} | ||
S3_TAGS: ${{ inputs.s3-tags }} | ||
# Only if we are using AWS S3 | ||
if: steps.info.outputs.configure-aws-credentials == 'true' && inputs.s3-tags != '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env bats | ||
|
||
load static-assets-info.sh | ||
|
||
function setup() { | ||
export AWS_ACCESS_KEY_ID='' | ||
export AWS_SECRET_ACCESS_KEY='' | ||
} | ||
|
||
function teardown() { | ||
: | ||
} | ||
|
||
@test "it should configure aws credentials" { | ||
export AWS_ACCESS_KEY_ID='foo' | ||
export AWS_SECRET_ACCESS_KEY='bar' | ||
|
||
run static-assets-info | ||
|
||
[ "$status" -eq 0 ] | ||
[[ "$output" =~ .*::set-output\ name=configure-aws-credentials::true ]] | ||
} | ||
|
||
@test "it should not configure aws credentials" { | ||
run static-assets-info | ||
|
||
[ "$status" -eq 0 ] | ||
[[ "$output" =~ .*::set-output\ name=configure-aws-credentials::false ]] | ||
} | ||
|
||
@test "it should error because access key id is missing" { | ||
export AWS_SECRET_ACCESS_KEY='bar' | ||
|
||
run static-assets-info | ||
|
||
[ "$status" -ne 0 ] | ||
} | ||
|
||
@test "it should error because secret access key is missing" { | ||
export AWS_ACCESS_KEY_ID='foo' | ||
|
||
run static-assets-info | ||
|
||
[ "$status" -ne 0 ] | ||
} |
Oops, something went wrong.