Skip to content

add the download package artifact #48

add the download package artifact

add the download package artifact #48

Workflow file for this run

name: Pipeline
on:
push:
branches:
- 'main'
- 'feature**'
- 'dev'
# dgieature**'
env:
SAM_TEMPLATE: template.yaml
DEV_STACK_NAME: sam-dev
DEV_PIPELINE_EXECUTION_ROLE: arn:aws:iam::381492285923:role/aws-sam-cli-managed-dev-pipel-PipelineExecutionRole-UaHDX0uHMlbb
DEV_CLOUDFORMATION_EXECUTION_ROLE: arn:aws:iam::381492285923:role/aws-sam-cli-managed-dev-p-CloudFormationExecutionRo-w8faWVZpG2wg
DEV_ARTIFACTS_BUCKET: aws-sam-cli-managed-dev-pipeline-r-artifactsbucket-hkgixjbuzwh8
# If there are functions with "Image" PackageType in your template,
# uncomment the line below and add "--image-repository ${DEV_IMAGE_REPOSITORY}" to
# DEV "sam package" and "sam deploy" commands.
# DEV_IMAGE_REPOSITORY = '0123456789.dkr.ecr.region.amazonaws.com/repository-name'
DEV_REGION: us-east-1
PROD_STACK_NAME: sam-prod
PROD_PIPELINE_EXECUTION_ROLE: arn:aws:iam::381492285923:role/aws-sam-cli-managed-prod-pipe-PipelineExecutionRole-nqfCgyJpQeCe
PROD_CLOUDFORMATION_EXECUTION_ROLE: arn:aws:iam::381492285923:role/aws-sam-cli-managed-prod--CloudFormationExecutionRo-XyodNvEhsqDv
PROD_ARTIFACTS_BUCKET: aws-sam-cli-managed-prod-pipeline--artifactsbucket-bmcqaivt57h4
# If there are functions with "Image" PackageType in your template,
# uncomment the line below and add "--image-repository ${PROD_IMAGE_REPOSITORY}" to
# prod "sam package" and "sam deploy" commands.
# PROD_IMAGE_REPOSITORY = '0123456789.dkr.ecr.region.amazonaws.com/repository-name'
PROD_REGION: us-east-1
permissions:
id-token: write
contents: read
jobs:
test:
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: |
# trigger the tests here
delete-feature:
if: startsWith(github.event.ref, 'feature') && github.event_name == 'delete'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: aws-actions/setup-sam@v2
with:
use-installer: true
- name: Assume the dev pipeline user role
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: ${{ env.DEV_REGION }}
role-to-assume: ${{ env.DEV_PIPELINE_EXECUTION_ROLE }}
role-session-name: dev-packaging
role-duration-seconds: 3600
role-skip-session-tagging: true
- name: Delete feature branch stack
env:
FEATURE_BRANCH_NAME: ${{ github.event.ref }}
run: |
sam delete \
--stack-name $(echo ${FEATURE_BRANCH_NAME##*/} | tr -cd '[a-zA-Z0-9-]') \
--region ${DEV_REGION} \
--no-prompts
build-and-deploy-feature:
# this stage is triggered only for feature branches (feature*),
# which will build the stack and deploy to a stack named with branch name.
# https://github.com/actions/setup-python
# https://github.com/aws-actions/configure-aws-credentials#notice-node12-deprecation-warning
if: startsWith(github.ref, 'refs/heads/feature')
needs: [test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: aws-actions/setup-sam@v2
with:
use-installer: true
- run: sam build --template ${SAM_TEMPLATE} --use-container
- name: Assume the DEV pipeline user role
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: ${{ env.DEV_REGION }}
role-to-assume: ${{ env.DEV_PIPELINE_EXECUTION_ROLE }}
role-session-name: feature-deployment
role-duration-seconds: 3600
role-skip-session-tagging: true
- name: Deploy to feature stack in the DEV account
shell: bash
run: |
sam deploy --stack-name $(echo ${GITHUB_REF##*/} | tr -cd '[a-zA-Z0-9-]') \
--capabilities CAPABILITY_IAM \
--region ${DEV_REGION} \
--s3-bucket ${DEV_ARTIFACTS_BUCKET} \
--no-fail-on-empty-changeset \
--role-arn ${DEV_CLOUDFORMATION_EXECUTION_ROLE}
build-and-package:
if: github.ref == 'refs/heads/dev'
needs: [test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: aws-actions/setup-sam@v2
with:
use-installer: true
- name: Build resources
run: sam build --template ${SAM_TEMPLATE} --use-container
- name: Assume the dev pipeline user role
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: ${{ env.DEV_REGION }}
role-to-assume: ${{ env.DEV_PIPELINE_EXECUTION_ROLE }}
role-session-name: dev-packaging
role-duration-seconds: 3600
role-skip-session-tagging: true
- name: Upload artifacts to DEV artifact buckets
run: |
sam package \
--s3-bucket ${DEV_ARTIFACTS_BUCKET} \
--region ${DEV_REGION} \
--output-template-file packaged-dev.yaml
- uses: actions/upload-artifact@v3
with:
name: packaged-dev.yaml
path: packaged-dev.yaml
- name: Assume the prod pipeline user role
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: ${{ env.PROD_REGION }}
role-to-assume: ${{ env.PROD_PIPELINE_EXECUTION_ROLE }}
role-session-name: prod-packaging
role-duration-seconds: 3600
role-skip-session-tagging: true
- name: Upload artifacts to production artifact buckets
run: |
sam package \
--s3-bucket ${PROD_ARTIFACTS_BUCKET} \
--region ${PROD_REGION} \
--output-template-file packaged-prod.yaml
- uses: actions/upload-artifact@v3
with:
name: packaged-prod.yaml
path: packaged-prod.yaml
deploy-dev:
if: github.ref == 'refs/heads/dev'
needs: [build-and-package]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: aws-actions/setup-sam@v2
with:
use-installer: true
- uses: actions/download-artifact@v3
with:
name: packaged-dev.yaml
- name: Assume the dev pipeline user role
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: ${{ env.DEV_REGION }}
role-to-assume: ${{ env.DEV_PIPELINE_EXECUTION_ROLE }}
role-session-name: dev-deployment
role-duration-seconds: 3600
role-skip-session-tagging: true
- name: Deploy to dev account
run: |
sam deploy --stack-name ${DEV_STACK_NAME} \
--template packaged-dev.yaml \
--capabilities CAPABILITY_IAM \
--region ${DEV_REGION} \
--s3-bucket ${DEV_ARTIFACTS_BUCKET} \
--no-fail-on-empty-changeset \
--role-arn ${DEV_CLOUDFORMATION_EXECUTION_ROLE}
# integration-test:
# if: github.ref == 'refs/heads/main'
# needs: [deploy-DEV]
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - run: |
# # trigger the integration tests here
deploy-prod:
if: github.ref == 'refs/heads/main'
needs: [deploy-dev]
runs-on: ubuntu-latest
# Configure GitHub Action Environment to have a manual approval step before deployment to production
# https://docs.github.com/en/actions/reference/environments
# environment: <configured-environment>
steps:
- uses: actions/checkout@v3
- uses: aws-actions/setup-sam@v2
with:
use-installer: true
# - uses: actions/download-artifact@v3
# with:
# name: packaged-prod.yaml
- name: Download packaged artifacts
uses: actions/download-artifact@v2
with:
name: packaged-prod.yaml
path: .
- name: Assume the prod pipeline user role
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: ${{ env.PROD_REGION }}
role-to-assume: ${{ env.PROD_PIPELINE_EXECUTION_ROLE }}
role-session-name: prod-deployment
role-duration-seconds: 3600
role-skip-session-tagging: true
- name: Deploy to production account
run: |
sam deploy --stack-name ${PROD_STACK_NAME} \
--template packaged-prod.yaml \
--capabilities CAPABILITY_IAM \
--region ${PROD_REGION} \
--s3-bucket ${PROD_ARTIFACTS_BUCKET} \
--no-fail-on-empty-changeset \
--role-arn ${PROD_CLOUDFORMATION_EXECUTION_ROLE}