From d2b38a15abe5dae3f9e4bc467da3df9d993e87f4 Mon Sep 17 00:00:00 2001 From: m-sureshraj Date: Sat, 6 Jan 2024 10:39:34 +0100 Subject: [PATCH] chore: move deploy job to its own workflow --- .github/workflows/deploy-to-dev-env.yml | 107 +++++++++--------- .../workflows/deployment-with-gh-actions.yml | 50 ++------ deployment-with-github-actions/package.json | 5 +- deployment-with-github-actions/serverless.yml | 1 + 4 files changed, 66 insertions(+), 97 deletions(-) diff --git a/.github/workflows/deploy-to-dev-env.yml b/.github/workflows/deploy-to-dev-env.yml index c6a0b8d..163feec 100644 --- a/.github/workflows/deploy-to-dev-env.yml +++ b/.github/workflows/deploy-to-dev-env.yml @@ -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' @@ -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 diff --git a/.github/workflows/deployment-with-gh-actions.yml b/.github/workflows/deployment-with-gh-actions.yml index 02be847..e44429a 100644 --- a/.github/workflows/deployment-with-gh-actions.yml +++ b/.github/workflows/deployment-with-gh-actions.yml @@ -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: @@ -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 @@ -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 @@ -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 diff --git a/deployment-with-github-actions/package.json b/deployment-with-github-actions/package.json index cdd54a5..67d3e80 100644 --- a/deployment-with-github-actions/package.json +++ b/deployment-with-github-actions/package.json @@ -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": "", diff --git a/deployment-with-github-actions/serverless.yml b/deployment-with-github-actions/serverless.yml index f4966aa..a1daf6b 100644 --- a/deployment-with-github-actions/serverless.yml +++ b/deployment-with-github-actions/serverless.yml @@ -3,6 +3,7 @@ frameworkVersion: '3' provider: name: aws + deploymentMethod: direct runtime: nodejs20.x region: eu-west-2 stage: ${opt:stage, 'dev'}