Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AhmedELShafaie/665add392914f815de5a8c0d29b46119 to your computer and use it in GitHub Desktop.
Save AhmedELShafaie/665add392914f815de5a8c0d29b46119 to your computer and use it in GitHub Desktop.

Revisions

  1. @ljmocic ljmocic revised this gist Apr 13, 2020. No changes.
  2. @ljmocic ljmocic revised this gist Apr 11, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions react-github-actions-workflow.yml
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    # Read more about setting it up
    # https://medium.com/@ljmocic/deploying-react-application-to-aws-s3-using-github-actions-85addacaeace

    on:
    push:
    tags:
  3. @ljmocic ljmocic revised this gist Apr 11, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions react-github-actions-workflow.yml
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # Read more about setting it up
    # https://medium.com/@ljmocic/deploying-react-application-to-aws-s3-using-github-actions-85addacaeace
    on:
    push:
    tags:
  4. @ljmocic ljmocic created this gist Mar 28, 2020.
    82 changes: 82 additions & 0 deletions react-github-actions-workflow.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,82 @@
    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 }}