Skip to content

chore(deps): update dependency git to v5 #244

chore(deps): update dependency git to v5

chore(deps): update dependency git to v5 #244

name: "Build & Publish COA image based on PRs"
on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
workflow_dispatch:
inputs:
pr_number:
description: 'PR number to build'
required: true
type: number
jobs:
publish:
name: "Build with source and publish on GHCR"
if: github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.fork == false
runs-on: ubuntu-latest
permissions:
contents: read
statuses: write
packages: write
env:
PR_NUMBER: ${{ github.event.pull_request.number || inputs.pr_number }}
PR_TAG: PR-${{ github.event.pull_request.number || inputs.pr_number }}
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
steps:
- name: Checkout PR head
uses: actions/checkout@v6
with:
ref: refs/pull/${{ env.PR_NUMBER }}/head
fetch-depth: 0
- name: Compute short SHA
run: |
SHORT_SHA="$(git rev-parse --short HEAD)"
echo "This is short sha #$SHORT_SHA for PR #$PR_NUMBER"
echo "SHORT_SHA=$SHORT_SHA" >> "$GITHUB_ENV"
- name: Set build-image status to pending
if: github.event_name != 'workflow_dispatch'
uses: actions/github-script@v9
with:
script: |
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: process.env.PR_HEAD_SHA,
state: 'pending',
context: 'build-image',
description: 'Building PR docker image (RN: ${context.runNumber}- SHA: ${process.env.SHORT_SHA})',
target_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
});
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Login to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push PR image
id: build
uses: docker/build-push-action@v7
with:
context: .
file: ./Dockerfile
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/cf-ops-automation:${{ env.PR_TAG }}-RN-${{ github.run_number }}-${{ env.SHORT_SHA }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Set build-image status to success
if: success() && github.event_name != 'workflow_dispatch'
uses: actions/github-script@v9
with:
script: |
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: process.env.PR_HEAD_SHA,
state: 'success',
context: 'build-image',
description: `Published ${process.env.PR_TAG}-RN-${context.runNumber}-${process.env.SHORT_SHA}`,
target_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/pkgs/container/cf-ops-automation`
});
- name: Set build-image status to failure
if: failure() && github.event_name != 'workflow_dispatch'
uses: actions/github-script@v9
with:
script: |
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: process.env.PR_HEAD_SHA,
state: 'failure',
context: 'build-image',
description: `Failed to publish ${process.env.PR_TAG}-RN-${context.runNumber}-${process.env.SHORT_SHA}`,
target_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
});