ci: Update ci-dev.yml #7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker Pipeline | ||
on: | ||
pushes: | ||
branches: | ||
- main | ||
paths: | ||
- 'package.json' | ||
workflow_dispatch: | ||
permissions: | ||
packages: write | ||
jobs: | ||
build-and-push-docker: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check for version change | ||
id: version_change | ||
run: | | ||
git fetch origin main:main | ||
VERSION_MAIN=$(git show main:package.json | jq -r '.version') | ||
VERSION_HEAD=$(jq -r '.version' package.json) | ||
if [ "$VERSION_MAIN" = "$VERSION_HEAD" ]; then | ||
echo "No version change detected, stopping workflow" | ||
echo "stop_early=true" >> $GITHUB_ENV | ||
fi | ||
- name: Checkout code | ||
if: env.stop_early != 'true' | ||
uses: actions/checkout@v4 | ||
- name: Check for dependency updates | ||
if: env.stop_early != 'true' | ||
id: check_updates | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
current_sha=$(git rev-parse HEAD) | ||
latest_sha=$(curl --silent --header "Authorization: token $GITHUB_TOKEN" \ | ||
https://api.github.com/repos/${{ github.repository }}/commits/${{ github.head_ref }} \ | ||
| jq -r '.sha') | ||
if [[ "$current_sha" != "$latest_sha" ]]; then | ||
echo "updated=true" >> "$GITHUB_OUTPUT" | ||
fi | ||
- name: Pull latest changes | ||
if: steps.check_updates.outputs.updated == 'true' | ||
run: git pull | ||
- name: Install jq | ||
if: env.stop_early != 'true' | ||
run: sudo apt-get install jq | ||
- name: Set up Docker Buildx | ||
if: env.stop_early != 'true' | ||
uses: docker/setup-buildx-action@v3 | ||
- name: login to GitHub Container Registry | ||
if: env.stop_early != 'true' | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Extract repository info | ||
if: env.stop_early != 'true' | ||
id: extract_info | ||
run: | | ||
echo "PACKAGE_VERSION=$(jq -r '.version' package.json)" >> "$GITHUB_OUTPUT" | ||
echo "PACKAGE_NAME=$(jq -r '.name' package.json)" >> "$GITHUB_OUTPUT" | ||
echo "REPOSITORY_NAME=$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT" | ||
- name: Build and push Docker image | ||
if: env.stop_early != 'true' | ||
id: docker_build | ||
uses: docker/build-push-action@v5 | ||
env: | ||
PACKAGE_VERSION: ${{ steps.extract_info.outputs.PACKAGE_VERSION }} | ||
PACKAGE_NAME: ${{ steps.extract_info.outputs.PACKAGE_NAME }} | ||
REPOSITORY_NAME: ${{ steps.extract_info.outputs.REPOSITORY_NAME }} | ||
with: | ||
context: . | ||
file: ./docker/Dockerfile | ||
push: true | ||
tags: ghcr.io/${{ env.REPOSITORY_NAME }}/${{ env.PACKAGE_NAME }}:${{ env.PACKAGE_VERSION }} | ||
load: true | ||
- name: Trigger Devtron Webhook | ||
if: env.stop_early != 'true' | ||
run: | | ||
curl --location --request POST \ | ||
'http://157.90.27.220:30673/orchestrator/webhook/ext-ci/1' \ | ||
--header 'Content-Type: application/json' \ | ||
--header "api-token: ${{ secrets.DEVTRON_API_TOKEN }}" \ | ||
--data-raw '{ | ||
"dockerImage": "ghcr.io/${{ env.REPOSITORY_NAME }}/${{ env.PACKAGE_NAME }}:${{ env.PACKAGE_VERSION }}", | ||
"digest": "${{ steps.docker_build.outputs.digest }}", | ||
"dataSource": "ext", | ||
"materialType": "git", | ||
"ciProjectDetails": [ | ||
{ | ||
"commitHash": "${{ github.sha }}", | ||
"message": "${{ github.event.head_commit.message }}", | ||
"author": "${{ github.actor }}", | ||
"commitTime": "${{ github.event.head_commit.timestamp }}" | ||
} | ||
] | ||
}' |