Skip to content

Passing branch name to checkout step #3

Passing branch name to checkout step

Passing branch name to checkout step #3

name: 'Brightspot AWS Deploy'
on:
workflow_call:
inputs:
region:
description: 'Region project is deployed to'
required: true
type: string
project:
description: 'Shortname for project'
required: true
type: string
repository:
description: 'Repository name. This overrides the default which is ${project}/${project}'
required: false
type: string
deploy-s3:
description: 'Deploy to S3 in addition to the container build'
required: false
default: false
type: boolean
deploy-bucket:
description: 'S3 bucket to deploy to'
required: false
type: string
deploy-bucket-prefix:
description: 'Directory prefix within the S3 bucket'
required: false
type: string
deploy-container:
description: 'Deploy to container build'
required: false
default: true
type: boolean
runs-on:
description: Platform to execute on
type: string
default: ubuntu-20.04-4core
secrets:
CLOUD_AWS_ACCESS_KEY_ID:
required: false
CLOUD_AWS_SECRET_ACCESS_KEY:
required: false
CLOUD_AWS_SESSION_TOKEN:
required: false
jobs:
build:
name: "AWS Cloud Deploy"
runs-on: ${{ inputs.runs-on }}
env:
aws_access_secret: ${{ secrets.AWS_ACCESS_KEY_ID }}
cloud_aws_access_secret: ${{ secrets.CLOUD_AWS_ACCESS_KEY_ID }}
opsdesk_api_client_id: ${{ secrets.OPSDESK_API_CLIENT_ID }}
# Map the job outputs to step outputs
outputs:
container-build-tag: ${{ steps.build-container.outputs.container-build-tag }}
container-version-tag: ${{ steps.build-container.outputs.container-version-tag }}
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: brightspot-build
path: brightspot-build
- name: Extract branch name
shell: bash

Check failure on line 77 in .github/workflows/aws-cloud-deploy.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/aws-cloud-deploy.yml

Invalid workflow file

You have an error in your yaml syntax on line 77
run: echo "branch_name=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
outputs:
branch_name: ${{ steps.create-branch.outputs.branch_name}}
- uses: actions/checkout@v4
with:
repository: perfectsense/brightspot-github-actions-workflows
ref: ${{ steps.extract_branch.outputs.branch_name }}
path: ./brightspot
- name: Get Tag Version
shell: bash
run: |
echo "GITHUB_ACTIONS_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
echo "GITHUB_ACTIONS_PULL_REQUEST=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
- name: Deploy to S3
if: ${{ inputs.deploy-s3 && env.aws_access_secret != '' }}
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_SESSION_TOKEN: ${{ secrets.AWS_SESSION_TOKEN }}
AWS_DEFAULT_REGION: ${{ inputs.region }}
DEPLOY_BUCKET: ${{ inputs.deploy-bucket }}
DEPLOY_BUCKET_PREFIX: ${{ inputs.deploy-bucket-prefix }}
DEPLOY_SOURCE_DIR: brightspot-build
shell: bash
run: ./brightspot/aws/aws-s3-deploy.sh
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
if: ${{ inputs.deploy-container && env.cloud_aws_access_secret != '' }}
with:
aws-access-key-id: ${{ secrets.CLOUD_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CLOUD_AWS_SECRET_ACCESS_KEY }}
aws-session-token: ${{ secrets.CLOUD_AWS_SESSION_TOKEN}}
aws-region: ${{ inputs.region }}
- name: ECR
if: ${{ inputs.deploy-container && env.cloud_aws_access_secret != '' }}
run: |
echo "Project ECR - ${{ vars.PROJECT_AWS_ACCOUNT_ID }}.dkr.ecr.${{ inputs.region }}.amazonaws.com"
echo "Brightspot Cloud ECR - ${{ vars.CLOUD_AWS_ACCOUNT_ID }}.dkr.ecr.${{ inputs.region }}.amazonaws.com"
- name: Login to project ECR
uses: docker/login-action@v3
if: ${{ inputs.deploy-container && env.cloud_aws_access_secret != '' }}
with:
registry: ${{ vars.PROJECT_AWS_ACCOUNT_ID }}.dkr.ecr.${{ inputs.region }}.amazonaws.com
- name: Login to Brightspot Cloud ECR
uses: docker/login-action@v3
if: ${{ inputs.deploy-container && env.cloud_aws_access_secret != '' }}
with:
registry: ${{ vars.CLOUD_AWS_ACCOUNT_ID }}.dkr.ecr.${{ inputs.region }}.amazonaws.com
- name: Build Container
id: build-container
if: ${{ inputs.deploy-container && env.cloud_aws_access_secret != '' }}
shell: bash
run: |
version=""
build=""
echo "GITHUB_ACTIONS_TAG ${GITHUB_ACTIONS_TAG}"
echo "GITHUB_ACTIONS_PULL_REQUEST ${GITHUB_ACTIONS_PULL_REQUEST}"
if [[ ! -z "$GITHUB_ACTIONS_PULL_REQUEST" && "$GITHUB_ACTIONS_PULL_REQUEST" != "" ]]; then
version="pullrequest-$GITHUB_ACTIONS_PULL_REQUEST"
build=pullrequest-$GITHUB_ACTIONS_PULL_REQUEST-build$GITHUB_RUN_NUMBER
elif [[ "$GITHUB_ACTIONS_TAG" =~ ^v[0-9]+\. ]]; then
echo "GITHUB_ACTIONS_TAG ${GITHUB_ACTIONS_TAG}"
version=release-${GITHUB_ACTIONS_TAG/v/}
build=release-${GITHUB_ACTIONS_TAG/v/}
else
COMMIT_COUNT=$(git rev-list --count HEAD)
COMMIT_SHA=$(git rev-parse --short=6 HEAD)
build=development-$(git describe --all | sed 's/heads\///' | sed 's/\//-/g')
build+=-build$GITHUB_RUN_NUMBER
version=development-$(git describe --all | sed 's/heads\///' | sed 's/\//-/g')
fi
cp brightspot-build/*.war etc/container/web.war
cd etc/container
PROJECT="${{ inputs.project }}"
REPOSITORY="${{ inputs.repository }}"
if [ -z ${REPOSITORY} ]; then
REPOSITORY="$PROJECT/$PROJECT"
fi
REGISTRY="${{ vars.PROJECT_AWS_ACCOUNT_ID }}.dkr.ecr.${{ inputs.region }}.amazonaws.com"
BUILD_TAG="$REGISTRY/$REPOSITORY:$build"
VERSION_TAG="$REGISTRY/$REPOSITORY:$version"
docker buildx build --push --build-arg WAR_ARTIFACT=web.war -t $VERSION_TAG -t $BUILD_TAG -f Dockerfile --metadata-file docker-metadata.json .
echo "container-build-tag=$(echo $BUILD_TAG)" >> $GITHUB_OUTPUT
echo "container-version-tag=$(echo $VERSION_TAG)" >> $GITHUB_OUTPUT
- uses: actions/download-artifact@v4
with:
name: brightspot-version
path: brightspot-version
- name: Upload Brightspot version
if: ${{ inputs.deploy-container && env.cloud_aws_access_secret != '' && env.opsdesk_api_client_id != '' }}
run: ./brightspot/analysis/opsdesk-post.sh brightspot-version/brightspot-version.txt ./etc/container/docker-metadata.json ${{ secrets.OPSDESK_API_CLIENT_ID }} ${{ secrets.OPSDESK_API_SECRET }}
shell: bash