Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/githubactions #12

Closed
wants to merge 10 commits into from
164 changes: 89 additions & 75 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI/CD for nautible front app

on:
push:
branches: [ "develop","feature/*","hotfix/*" ]
branches: ['develop', 'feature/*', 'hotfix/*']
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
workflow_dispatch:

permissions:
id-token: write
Expand All @@ -15,76 +15,90 @@ jobs:
runs-on: ubuntu-latest
environment: develop # for azure oidc
steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: setup node
uses: actions/setup-node@v1
with:
node-version: '18.x'

- name: Cache node modules
uses: actions/cache@v2
with:
path: ./app/node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

# AWS
- name: setup env file for aws
run: |
cd $GITHUB_WORKSPACE/app
sed -e "s/\$domain/${{ secrets.AWS_CLOUDFRONT_DOMAIN }}/" .env.auth-sample > .env

- name: Build for aws
env:
CI: false
run: |
cd $GITHUB_WORKSPACE/app
yarn
yarn build

- name: Test for aws
env:
CI: false
run: |
cd $GITHUB_WORKSPACE/app
yarn test

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/nautible-dev-githubactions-static-web-deploy-role
aws-region: ap-northeast-1

- name: deploy to aws s3
run: |
cd $GITHUB_WORKSPACE/app
aws s3 sync ./build s3://${{ secrets.AWS_S3_STATIC_WEB_BUCKET }} --exclude "*.git/*" --delete

# Azure
- name: setup env file for azure
run: |
cd $GITHUB_WORKSPACE/app
sed -e "s/\$domain/${{ secrets.AZURE_FRONTDOOR_DOMAIN }}/" .env.auth-sample > .env

- name: Build for azure
env:
CI: false
run: |
cd $GITHUB_WORKSPACE/app
yarn
yarn build

- name: Azure Login
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

- name: deploy to azure storage account
run: |
cd $GITHUB_WORKSPACE/app
az storage blob upload-batch --account-name nautibledevstaticweb -d '$web' -s ./build --overwrite=True
- name: Checkout repo
uses: actions/checkout@v4

- name: setup node
uses: actions/setup-node@v4
with:
node-version: '18'

- name: Cache node modules
uses: actions/cache@v4
with:
path: ./app/node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

# AWS
- name: setup env file for aws
run: |
cd $GITHUB_WORKSPACE/app
sed -e "s/\$domain/${{ secrets.AWS_CLOUDFRONT_DOMAIN }}/" .env.auth-sample > .env

- name: Build for aws
env:
CI: false
run: |
cd $GITHUB_WORKSPACE/app
yarn
yarn build

- name: Test for aws
env:
CI: false
run: |
cd $GITHUB_WORKSPACE/app
yarn test

- name: Configure AWS credentials
id: login-aws
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/nautible-dev-githubactions-static-web-deploy-role
aws-region: ap-northeast-1
continue-on-error: true

- name: login-aws when command failure
run: echo "result - aws login failure"
if: steps.login-aws.outcome == 'failure'

- name: deploy to aws s3
run: |
cd $GITHUB_WORKSPACE/app
aws s3 sync ./build s3://${{ secrets.AWS_S3_STATIC_WEB_BUCKET }} --exclude "*.git/*" --delete
if: steps.login-aws.outcome == 'success'

# Azure
- name: setup env file for azure
run: |
cd $GITHUB_WORKSPACE/app
sed -e "s/\$domain/${{ secrets.AZURE_FRONTDOOR_DOMAIN }}/" .env.auth-sample > .env

- name: Build for azure
env:
CI: false
run: |
cd $GITHUB_WORKSPACE/app
yarn
yarn build

- name: Azure Login
id: login-azure
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
continue-on-error: true

- name: login-azure when command failure
run: echo "result - azure login failure"
if: steps.login-azure.outcome == 'failure'

- name: deploy to azure storage account
run: |
cd $GITHUB_WORKSPACE/app
az storage blob upload-batch --account-name nautibledevstaticweb -d '$web' -s ./build --overwrite=True
if: steps.login-azure.outcome == 'success'
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@types/react-dom": "^18.0.8",
"@types/react-router-dom": "^5.3.3",
"axios": "^1.1.3",
"keycloak-js": "18.0.0",
"keycloak-js": "25.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.4.2",
Expand Down
Loading