-
Notifications
You must be signed in to change notification settings - Fork 6
71 lines (70 loc) · 2.84 KB
/
s3-resources-upload.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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