Skip to content

Commit

Permalink
chore: move deploy job to its own workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
m-sureshraj committed Jan 6, 2024
1 parent d0474b9 commit d2b38a1
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 97 deletions.
107 changes: 55 additions & 52 deletions .github/workflows/deploy-to-dev-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: deploy the selected branch to development (dev) deployment
on:
workflow_dispatch:

#permissions:
# id-token: write # This is required for requesting the JWT
# contents: read # This is required for actions/checkout
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout

env:
AWS_REGION : 'eu-west-2'
Expand All @@ -14,57 +14,60 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
# - name: ⬇️ Checkout repo
# uses: actions/checkout@v4
#
# - name: ⎔ Setup node
# uses: actions/setup-node@v4
# with:
# node-version: 18
- name: ⬇️ Checkout repo
uses: actions/checkout@v4

- name: print the branch name
# working-directory: ./deployment-with-github-actions
run: |
echo "GITHUB_BASE_REF - ${{ github.base_ref }}"
echo "GITHUB_HEAD_REF - ${{ github.head_ref }}"
echo "GITHUB_REF - ${{ github.ref }}"
echo "GITHUB_REF_NAME - ${{ github.ref_name }}"
- name: ⎔ Setup node
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
cache-dependency-path: ./deployment-with-github-actions/package-lock.json

# - name: Unit test
# working-directory: ./deployment-with-github-actions
# run: npm run test
- name: Install dependencies
working-directory: ./deployment-with-github-actions
run: npm ci

- name: Unit test
working-directory: ./deployment-with-github-actions
run: npm run test

- name: Package
working-directory: ./deployment-with-github-actions
run: npm run package

deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Git clone the repository
uses: actions/checkout@v4

- name: ⎔ Setup node
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
working-directory: ./deployment-with-github-actions
run: npm ci

- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
with:
mask-aws-account-id: true
role-to-assume: ${{ secrets.AWS_GITHUB_ACTIONS_ROLE_ARN }}
role-session-name: github-action-sls-examples
aws-region: ${{ env.AWS_REGION }}

- name: versions
working-directory: ./deployment-with-github-actions
run: |
echo "printing working directory - $(pwd)"
echo "node version - $(node -v)"
echo "aws cli version - $(aws --version)"
echo "sls version - $(./node_modules/.bin/sls --version)"
# deploy:
# needs: build
# runs-on: ubuntu-latest
# steps:
# - name: Git clone the repository
# uses: actions/checkout@v4
#
# - name: ⎔ Setup node
# uses: actions/setup-node@v4
# with:
# node-version: 18
#
# - name: Install dependencies
# working-directory: ./deployment-with-github-actions
# run: npm ci
#
# - name: configure aws credentials
# uses: aws-actions/configure-aws-credentials@v4
# with:
# mask-aws-account-id: true
# role-to-assume: ${{ secrets.AWS_GITHUB_ACTIONS_ROLE_ARN }}
# role-session-name: github-action-sls-examples
# aws-region: ${{ env.AWS_REGION }}
#
# - name: versions
# working-directory: ./deployment-with-github-actions
# run: |
# pwd
# node -v
# aws --version
#
# - name: deploy
# working-directory: ./deployment-with-github-actions
# run: npm run deploy:dev
# run: ./node_modules/.bin/sls deploy
50 changes: 7 additions & 43 deletions .github/workflows/deployment-with-gh-actions.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# This workflow is associated with the `/deployment-with-github-actions` example directory.
# It demonstrates the use of GH actions to build and

name: example dir `deployment-with-github-actions` deployment

on:
Expand All @@ -13,13 +16,6 @@ on:
paths:
- 'deployment-with-github-actions/**'

permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout

env:
AWS_REGION : 'eu-west-2'

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -30,7 +26,7 @@ jobs:
- name: ⎔ Setup node
uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20

- name: Install dependencies
working-directory: ./deployment-with-github-actions
Expand All @@ -40,38 +36,6 @@ jobs:
working-directory: ./deployment-with-github-actions
run: npm run test

deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Git clone the repository
uses: actions/checkout@v4

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

- name: Install dependencies
working-directory: ./deployment-with-github-actions
run: npm ci

- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
with:
mask-aws-account-id: true
role-to-assume: ${{ secrets.AWS_GITHUB_ACTIONS_ROLE_ARN }}
role-session-name: github-action-sls-examples
aws-region: ${{ env.AWS_REGION }}

- name: versions
working-directory: ./deployment-with-github-actions
run: |
pwd
node -v
aws --version
- name: deploy
working-directory: ./deployment-with-github-actions
# run: npm run deploy:dev
run: echo "this is a dry run..."
- name: Package
working-directory: ./deployment-with-github-actions
run: npm run package
5 changes: 3 additions & 2 deletions deployment-with-github-actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"description": "",
"type": "module",
"scripts": {
"deploy:dev": "serverless deploy --stage dev",
"test": "echo \"no test specified\""
"deploy:dev": "sls deploy --stage dev",
"test": "echo \"no test specified\"",
"package": "sls package"
},
"keywords": [],
"author": "",
Expand Down
1 change: 1 addition & 0 deletions deployment-with-github-actions/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ frameworkVersion: '3'

provider:
name: aws
deploymentMethod: direct
runtime: nodejs20.x
region: eu-west-2
stage: ${opt:stage, 'dev'}
Expand Down

0 comments on commit d2b38a1

Please sign in to comment.