Skip to content

Commit

Permalink
config update for buildnumber
Browse files Browse the repository at this point in the history
  • Loading branch information
priyaranjanpatil committed Jan 15, 2024
1 parent cdc4011 commit 02ba4bb
Showing 1 changed file with 33 additions and 31 deletions.
64 changes: 33 additions & 31 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ jobs:
steps:
- name: Git clone the repository
uses: actions/checkout@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.ROLE_ARN }}
role-session-name: GitHub_to_AWS_via_FederatedOIDC
aws-region: ${{ vars.AWS_REGION }}

# Hello from AWS: WhoAmI
- name: Sts GetCallerIdentity
run: |
Expand Down Expand Up @@ -100,11 +102,12 @@ jobs:
fi
done
- name: Prepare
- name: Prepare Build-ID
id: prep
run: |
BRANCH=${GITHUB_REF##*/}
TS=$(date +%s)
TS=$(date +%F%H%M%S | sed 's/-//g')
echo "TimeStamp=$TS"
REVISION=${GITHUB_SHA::8}
BUILD_ID="${BRANCH}-${REVISION}-${TS}"
LATEST_ID=canary
Expand All @@ -116,6 +119,32 @@ jobs:
echo "LATEST_ID=$LATEST_ID"
echo "BUILD_ID=$BUILD_ID" >> $GITHUB_OUTPUT
- name: Get and calculate latest package version - AWS CodeArtifact
id: ca-getversion
env:
BUILD_ID: ${{ steps.prep.outputs.BUILD_ID }}
run: |
FLAG_INITIAL=false
CURRENT_VERSION=$(aws codeartifact list-package-versions --domain $CA_DOMAIN --repository $CA_REPO --format generic --package $CA_PACKAGE --namespace $CA_NAMESPACE --query defaultDisplayVersion | jq -r ".")
echo "current version: $CURRENT_VERSION"
if [ -z "$CURRENT_VERSION" ] || [ "$CURRENT_VERSION" == "null" ]; then
CURRENT_VERSION="1.0.0"
FLAG_INITIAL=true
fi
IFS='.' read -ra version_parts <<< "$CURRENT_VERSION"
MAJOR=${version_parts[0]}
MINOR=${version_parts[1]}
NEW_MINOR=$((MINOR + 1))
if [ "$FLAG_INITIAL" == "true" ]; then
NEW_MINOR="0"
fi
#version format[major.minor.build_number]
#build_number format{BRANCH}-${REVISION}-${TS}
echo "latest_version=v$MAJOR.$NEW_MINOR.${{ env.BUILD_ID }}" >> $GITHUB_OUTPUT
- name: Checkout
uses: actions/checkout@v3

Expand All @@ -136,8 +165,7 @@ jobs:
- name: Build and tag image
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ steps.prep.outputs.BUILD_ID }}
IMAGE_TAG: ${{ steps.ca-getversion.outputs.latest_version }}
run: |
# Build a docker container and
# be deployed to ECS.
Expand All @@ -161,8 +189,7 @@ jobs:
- name: Push image to Amazon ECR
id: push-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ steps.prep.outputs.BUILD_ID }}
IMAGE_TAG: ${{ steps.ca-getversion.outputs.latest_version }}
run: |
# Build a docker container and
# be deployed to ECS.
Expand Down Expand Up @@ -223,31 +250,6 @@ jobs:
echo "Deployment successfull."
fi
- name: Get and calculate latest package version - AWS CodeArtifact
id: ca-getversion
env:
BUILD_ID: ${{ steps.prep.outputs.BUILD_ID }}
run: |
FLAG_INITIAL=false
CURRENT_VERSION=$(aws codeartifact list-package-versions --domain $CA_DOMAIN --repository $CA_REPO --format generic --package $CA_PACKAGE --namespace $CA_NAMESPACE --query defaultDisplayVersion | jq -r ".")
echo "current version: $CURRENT_VERSION"
if [ -z "$CURRENT_VERSION" ]; then
CURRENT_VERSION="1.0.0"
FLAG_INITIAL=true
fi
IFS='.' read -ra version_parts <<< "$CURRENT_VERSION"
MAJOR=${version_parts[0]}
MINOR=${version_parts[1]}
NEW_MINOR=$((MINOR + 1))
if [ "$FLAG_INITIAL" == "true" ]; then
NEW_MINOR="0"
fi
#version format[major.minor.build_number]
#build_number format{BRANCH}-${REVISION}-${TS}
echo "latest_version=$MAJOR.$NEW_MINOR.${{ env.BUILD_ID }}" >> $GITHUB_OUTPUT
- name: Publish JAR file - AWS CodeArtifact
id: ca-deploy
env:
Expand Down

0 comments on commit 02ba4bb

Please sign in to comment.