Forked from ljmocic/react-github-actions-workflow.yml
Created
September 6, 2021 10:56
-
-
Save truongluu/cf9856aefaf33989fa96d66018378a0b to your computer and use it in GitHub Desktop.
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
# Read more about setting it up | |
# https://medium.com/@ljmocic/deploying-react-application-to-aws-s3-using-github-actions-85addacaeace | |
on: | |
push: | |
tags: | |
- '*' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Clone repository | |
uses: actions/checkout@v2 | |
- name: Use Node.js 12.x | |
uses: actions/setup-node@v1 | |
with: | |
node-version: 12.x | |
- name: Install dependencies | |
run: npm install | |
- name: Test | |
run: npm test | |
env: | |
CI: true | |
- name: Generate build | |
run: npm run build | |
# Share artifact inside workflow | |
- name: Share artifact inside workflow | |
uses: actions/upload-artifact@v1 | |
with: | |
name: react-github-actions-build | |
path: build | |
deploy: | |
runs-on: ubuntu-latest | |
# When application is successfully tested and build has been generated | |
# Then we can start with deployment | |
needs: build | |
steps: | |
# Download previously shared build | |
- name: Get artifact | |
uses: actions/download-artifact@v1 | |
with: | |
name: react-github-actions-build | |
# Set the credentials from repository settings/secrets | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_DEFAULT_REGION }} | |
# Copy the files from build folder to the S3 bucket | |
- name: Deploy to S3 | |
run: aws s3 sync . s3://react-github-actions --acl public-read | |
working-directory: react-github-actions-build | |
release: | |
runs-on: ubuntu-latest | |
# We specify that deploys needs to | |
# finish before we create a release | |
needs: deploy | |
steps: | |
# Download previously shared build | |
- name: Get artifact | |
uses: actions/download-artifact@v1 | |
with: | |
name: react-github-actions-build | |
# Zip the build using external action | |
- name: Zip build | |
uses: thedoctor0/zip-release@master | |
with: | |
filename: react-github-actions-release-build.zip | |
path: react-github-actions-build | |
# Upload as an artifact of the current workflow | |
- name: Upload build zip artifact | |
uses: actions/upload-artifact@v1 | |
with: | |
name: react-github-actions-release-build.zip | |
path: react-github-actions-release-build.zip | |
# Make official GitHub release which will trigger | |
# sending the mail with link for access | |
- name: Release | |
uses: ncipollo/release-action@v1 | |
with: | |
artifacts: react-github-actions-release-build.zip | |
body: https://react-github-actions.s3.amazonaws.com/index.html | |
token: ${{ secrets.GITHUB_TOKEN }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment