Skip to content

remove head from peter-evans/create-pull-request #10

remove head from peter-evans/create-pull-request

remove head from peter-evans/create-pull-request #10

Workflow file for this run

name: Build and Push Docker Image
on:
push:
branches:
- app
permissions:
contents: write
pull-requests: write
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: Create a pull request from app to main if build succeeds
- name: Create Pull Request
if: success()
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Merge 'app' into 'main'"
base: main
title: "Automated PR: Merge 'app' into 'main'"
body: "This PR merges the 'app' branch into the 'main' branch automatically after the CI pipeline succeeds."
labels: "automated-pr"