Skip to content

Upload learning resources to S3 #31

Upload learning resources to S3

Upload learning resources to S3 #31

name: Upload learning resources to S3
on:
workflow_dispatch:
branches:
- main
- master
- draft
inputs:
environment:
type: choice
description: 'Set environment to upload resources to'
options:
- "PRODUCTION"
- "STAGING"
required: true
push:
branches:
- main
- master
- draft
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
jobs:
matrix:
name: 'Environment Matrix'
runs-on: ubuntu-latest
steps:
- id: set-matrix
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
if [[ ! -z "${{ github.event.inputs.environment }}" ]]; then
echo '::set-output name=matrix::{"environment":["${{ github.event.inputs.environment }}"]}'
else
echo '::set-output name=matrix::{}'
fi
elif [[ "${{ github.event_name }}" == "push" ]]; then
echo '::set-output name=matrix::{"environment":["PRODUCTION","STAGING"]}'
else
echo '::set-output name=matrix::{}'
fi
outputs:
matrix: ${{steps.set-matrix.outputs.matrix}}
s3-resources-upload:
name: 'S3 Upload - ${{ matrix.environment }}'
needs: matrix
runs-on: ubuntu-latest
strategy:
matrix: ${{fromJSON(needs.matrix.outputs.matrix)}}
if: ${{ needs.matrix.outputs.matrix != '{}' }}
steps:
- name: Debug Environment
run: |
echo "Setting environment to ${{ matrix.environment }}"
- uses: actions/checkout@v3
if: matrix.environment == 'PRODUCTION' || matrix.environment == 'STAGING'
- name: Configure AWS Credentials
if: matrix.environment == 'PRODUCTION' || matrix.environment == 'STAGING'
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets[format('AWS_ACCESS_KEY_ID_{0}', matrix.environment)] }}
aws-secret-access-key: ${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', matrix.environment)] }}
aws-region: eu-west-2
- name: Deploy static assets to S3 bucket
if: matrix.environment == 'PRODUCTION' || matrix.environment == 'STAGING'
run: |
if [[ "${{ matrix.environment }}" == "PRODUCTION" ]]; then
aws s3 sync . s3://learning-resources-production/projects/${{ github.event.repository.name }}/${{ github.sha }}/ --exclude "*" --include "*/images/*" --include "*/resources/*" --include "*/solutions/*" --delete --size-only --no-follow-symlinks
elif [[ "${{ matrix.environment }}" == "STAGING" ]]; then
aws s3 sync . s3://learning-resources-dev-staging/projects/${{ github.event.repository.name }}/${{ github.sha }}/ --exclude "*" --include "*/images/*" --include "*/resources/*" --include "*/solutions/*" --delete --size-only --no-follow-symlinks
fi