Skip to content

add github action step to merge 'app' into 'main' on successful job c… #4

add github action step to merge 'app' into 'main' on successful job c…

add github action step to merge 'app' into 'main' on successful job c… #4

Workflow file for this run

name: Build and Push Docker Image
on:
push:
branches:
- app
jobs:
build:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the latest code from the repo
- name: Checkout code
uses: actions/checkout@v4
# Step 2: Install jq to parse package.json
- name: Install jq
run: sudo apt-get install -y jq
# Step 3: Set up Docker in the workflow
- name: Set up Docker
uses: docker/setup-buildx-action@v3
# Step 4: Log in to Docker Hub using secrets
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}
# Step 5: Extract version from package.json
- name: Extract version from package.json
id: get_version
run: |
VERSION=$(cat app/package.json | jq -r .version)
echo "VERSION=$VERSION"
echo "::set-output name=version::$VERSION"
# Step 6: Build Docker image with version tag
- name: Build Docker image
run: |
docker build -t ${{ secrets.DOCKER_USER }}/gitops-app:${{ steps.get_version.outputs.version }} app/.
# Step 7: Push Docker image to Docker Hub
- name: Push Docker image
run: |
docker push ${{ secrets.DOCKER_USER }}/gitops-app:${{ steps.get_version.outputs.version }}
# Step 8: Merge app branch into main if build succeeds
- name: Merge app branch into main
if: success() # Only run this step if all previous steps succeeded
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "GitHub Actions"
git checkout main
git merge --no-ff app
git push origin main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}