Skip to content

Commit

Permalink
Refactors actions for future naming convention (#6)
Browse files Browse the repository at this point in the history
- Uses `setup-${language}` for setup actions.
- Makes actions specific to IaaS.
- Adds patterns to wrap actions into pre-prescribed flows.

## Breaking Changes

- Moves npm-setup to setup-node for future consistency
- Removes the npm-run action
- Renames the deploy-static-assets to deploy-to-s3-bucket
  • Loading branch information
mike-carey authored Feb 3, 2022
1 parent 79100d0 commit f086b69
Show file tree
Hide file tree
Showing 45 changed files with 777 additions and 482 deletions.
53 changes: 53 additions & 0 deletions .github/actions/test-deploy-to-s3-bucket/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---

name: 'Test deploy-to-s3-bucket action'
description: 'Runs validation agains the deploy-to-s3-bucket action'

inputs:
aws-account-id:
description: 'The AWS Account id'
required: true

runs:
using: 'composite'
steps:
- name: 'Install BATS and jq'
shell: bash
run: brew install bats-core jq

- name: 'Checkout'
uses: actions/checkout@v2

- name: 'Use local actions'
uses: ./.github/actions/use-local-actions

- name: 'Get unique id'
id: id
shell: bash
run: echo "::set-output name=id::$(date '+%s')"

- name: 'Create archive file'
shell: bash
run: tar -zcvf archive.tgz -C ${{ github.action_path }}/assets .

- name: 'Run deploy-to-s3-bucket action'
id: unpack
uses: ./actions/deploy-to-s3-bucket
with:
pattern: 'archive.tgz'
s3-bucket: shopsmart-github-actions-tests
s3-bucket-path: ${{ steps.id.outputs.id }}
role-to-assume: arn:aws:iam::${{ inputs.aws-account-id }}:role/github-actions-tests

- name: 'Configure AWS Credentials'
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: 'us-east-1'
role-to-assume: arn:aws:iam::${{ inputs.aws-account-id }}:role/github-actions-tests

- name: 'Validate'
shell: bash
run: bats -r ${{ github.action_path }}/deploy-to-s3-bucket.bats
env:
S3_BUCKET: shopsmart-github-actions-tests
S3_BUCKET_PATH: ${{ steps.id.outputs.id }}
1 change: 1 addition & 0 deletions .github/actions/test-deploy-to-s3-bucket/assets
28 changes: 28 additions & 0 deletions .github/actions/test-deploy-to-s3-bucket/deploy-to-s3-bucket.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bats

function setup() {
:
}

function teardown() {
:
}

@test "it should have deployed the assets to the s3 bucket" {
run aws s3 cp --recursive "s3://$S3_BUCKET/$S3_BUCKET_PATH" "$BATS_TEST_TMPDIR"

[ "$status" -eq 0 ]
[ -f "$BATS_TEST_TMPDIR/index.html" ]
[ -f "$BATS_TEST_TMPDIR/style.css" ]
}

# @test "it should have set the tag on all assets" {
# run aws s3api get-object-tagging \
# --bucket $S3_BUCKET \
# --key $S3_BUCKET_PATH/index.html \
# --no-cli-pager \
# | jq -r '.TagSet | to_entries[] | select(.key == "version")'

# [ "$status" -eq 0 ]
# [ "$output" = "$VERSION" ]
# }
31 changes: 31 additions & 0 deletions .github/actions/test-package-archive/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---

name: 'Test package-archive action'
description: 'Runs validation agains the package-archive action'

runs:
using: 'composite'
steps:
- name: 'Install BATS'
shell: bash
run: brew install bats-core

- name: 'Checkout'
uses: actions/checkout@v2

- name: 'Save off action path'
id: path
shell: bash
run: echo "::set-output name=path::${{ github.action_path }}"

- name: 'Run package-archive action'
id: unpack
uses: ./actions/package-archive
with:
directory: ${{ github.action_path }}/assets

- name: 'Validate'
shell: bash
run: bats -r ${{ github.action_path }}/package-archive.bats
env:
FILENAME: ${{ steps.unpack.outputs.filename }}
1 change: 1 addition & 0 deletions .github/actions/test-package-archive/assets
23 changes: 23 additions & 0 deletions .github/actions/test-package-archive/package-archive.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bats

function setup() {
:
}

function teardown() {
:
}

@test "it should have passed on the filename" {
[ -n "$FILENAME" ]
}

@test "it should package the archive file" {
[ -f "$FILENAME" ]

run tar -xf "$FILENAME" -C "$BATS_TEST_TMPDIR" .

[ "$status" -eq 0 ]
[ -f "$BATS_TEST_TMPDIR/index.html" ]
[ -f "$BATS_TEST_TMPDIR/style.css" ]
}
34 changes: 34 additions & 0 deletions .github/actions/test-setup-node/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---

name: 'Test setup-node'
description: 'Runs validation agains the setup-node action'

runs:
using: 'composite'
steps:
- name: 'Install BATS'
shell: bash
run: brew install bats-core

- name: 'Checkout actions'
uses: actions/checkout@v2

- name: 'Checkout hello world project'
uses: actions/checkout@v2
with:
repository: mike-carey/hello-world-nodejs
path: ./hello-world

- name: 'Run setup-node action'
id: setup
uses: ./actions/setup-node
with:
node-version: '14'
working-directory: ./hello-world

- name: 'Validate'
shell: bash
run: bats -r ${{ github.action_path }}/setup-node.bats
env:
DIRECTORY: ./hello-world
NODE_VERSION: ${{ steps.setup.outputs.node-version }}
21 changes: 21 additions & 0 deletions .github/actions/test-setup-node/setup-node.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bats

@test "it should have node installed" {
run node --version

[ "$status" -eq 0 ]
}

@test "it should have npm installed" {
run npm --version

[ "$status" -eq 0 ]
}

@test "it should have installed node_modules" {
[ -d "$DIRECTORY/node_modules" ]
}

@test "it should have passed along the node version" {
[ -n "$NODE_VERSION" ]
}
31 changes: 31 additions & 0 deletions .github/actions/test-unpack-archive/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---

name: 'Test unpack-archive action'
description: 'Runs validation agains the unpack-archive action'

runs:
using: 'composite'
steps:
- name: 'Install BATS'
shell: bash
run: brew install bats-core

- name: 'Checkout'
uses: actions/checkout@v2

- name: 'Create archive file'
shell: bash
run: tar -zcvf archive.tgz -C ${{ github.action_path }}/assets .

- name: 'Run unpack-archive action'
id: unpack
uses: ./actions/unpack-archive
with:
filename: 'archive.tgz'

- name: 'Validate'
shell: bash
run: bats -r ${{ github.action_path }}/unpack-archive.bats
env:
DESTINATION: ${{ steps.unpack.outputs.destination }}
MIME_TYPE: ${{ steps.unpack.outputs.mime-type }}
1 change: 1 addition & 0 deletions .github/actions/test-unpack-archive/assets
14 changes: 14 additions & 0 deletions .github/actions/test-unpack-archive/unpack-archive.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bats

@test "it should have passed along the destination" {
[ -n "$DESTINATION" ]
}

@test "it should have passed along the mime type" {
[ -n "$MIME_TYPE" ]
}

@test "it should have unpacked the archive file" {
[ -f "$DESTINATION/index.html" ]
[ -f "$DESTINATION/style.css" ]
}
2 changes: 1 addition & 1 deletion .github/actions/use-local-actions/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ runs:
steps:
- name: 'Use local actions'
shell: bash
run: $GITHUB_ACTION_PATH/use-local-actions.sh
run: ${{ github.action_path }}/use-local-actions.sh
43 changes: 0 additions & 43 deletions .github/workflows/test-deploy-static-assets.yml

This file was deleted.

30 changes: 30 additions & 0 deletions .github/workflows/test-deploy-to-s3-bucket.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---

name: 'Run deploy-to-s3-bucket action'

on:
pull_request:
paths:
- actions/deploy-to-s3-bucket/*
- actions/unpack-archive/*

permissions:
id-token: write
contents: read

defaults:
run:
shell: bash

jobs:
test-deploy-to-s3-bucket-action:
name: 'Uses the deploy-to-s3-bucket action'
runs-on: ubuntu-latest
steps:
- name: 'Checkout actions'
uses: actions/checkout@v2

- name: 'Test deploy-to-s3-bucket action'
uses: ./.github/actions/test-deploy-to-s3-bucket
with:
aws-account-id: ${{ secrets.AWS_ACCOUNT_ID }}
37 changes: 0 additions & 37 deletions .github/workflows/test-npm-run.yml

This file was deleted.

Loading

0 comments on commit f086b69

Please sign in to comment.