Skip to content

Commit

Permalink
Merge pull request #36 from jsoref/split-build-and-push-for-fork
Browse files Browse the repository at this point in the history
Split build and push step in two for PRs
  • Loading branch information
rchakode authored Jul 30, 2023
2 parents 3f5639d + ba24967 commit 6f56b67
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions .github/workflows/build-image-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,26 @@ jobs:
with:
fetch-depth: 0

- name: Build and push Docker image
- name: Build Docker image
env:
IMAGE_BASENAME: rchakode/realopinsight
REGISTRY_USERNAME: ${{ secrets.CONTAINER_REGISTRY_USERNAME }}
REGISTRY_PASSWORD: ${{ secrets.CONTAINER_REGISTRY_PASSWORD }}
run: |
echo "setting build version"
RELEASE_VERSION="$(date +%F)-$(git rev-parse --short HEAD)"
export RELEASE_VERSION="$(date +%F)-$(git rev-parse --short HEAD)"
VERSION_FILE=realopinsight.pro
VERSION_LINE=$(grep -n '^PACKAGE_VERSION=' $VERSION_FILE | cut -f1 -d:)
VERSION_ORIG=$(grep '^PACKAGE_VERSION=' $VERSION_FILE | cut -d= -f2)
sed -i "${VERSION_LINE}s/${VERSION_ORIG}/${RELEASE_VERSION}/" $VERSION_FILE
perl -pi -e 's/^(PACKAGE_VERSION=).*/$1$ENV{RELEASE_VERSION}/' $VERSION_FILE
cat $VERSION_FILE
echo "building container image => ${IMAGE_BASENAME}:${RELEASE_VERSION}"
IMAGE_TAGGED_NAME=${IMAGE_BASENAME}:${RELEASE_VERSION}
docker build -t ${IMAGE_TAGGED_NAME} .
echo "IMAGE_TAGGED_NAME=$IMAGE_TAGGED_NAME" >> "$GITHUB_ENV"
- name: Push Docker image
if: github.event.pull_request.head.repo.full_name == github.repository
env:
REGISTRY_USERNAME: ${{ secrets.CONTAINER_REGISTRY_USERNAME }}
REGISTRY_PASSWORD: ${{ secrets.CONTAINER_REGISTRY_PASSWORD }}
run: |
docker login --username ${REGISTRY_USERNAME} --password ${REGISTRY_PASSWORD}
docker push $IMAGE_TAGGED_NAME

0 comments on commit 6f56b67

Please sign in to comment.