Skip to content

Release and Publish Docker image #9

Release and Publish Docker image

Release and Publish Docker image #9

Workflow file for this run

name: Build, Test, Release, and Publish
run-name: Release and Publish Docker image
on:
push:
branches:
- tesci
env:
VERSION: "" # Définition initiale de la variable
jobs:
test-app:
name: Test App
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
create_release:
name: Create Release
runs-on: ubuntu-latest
needs: test-app
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get version from package.json
id: get_version
run: |
VERSION=$(jq -r .version package.json)
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
with:
tag_name: "v${{ env.VERSION }}"
release_name: "Release v${{ env.VERSION }}"
draft: false
prerelease: false
build-docker-prod:
runs-on: ubuntu-latest
needs: [test-app, create_release]
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ghcr.io/${{ github.repository_owner }}/patrigma:v${{ env.VERSION }} # Utilisation de la variable VERSION globale
labels: "version=${{ env.VERSION }},commit=${{ github.sha }}"
notify:
runs-on: ubuntu-latest
needs: build-docker-prod
steps:
- name: Notify Discord on failure
if: failure()
uses: containrrr/shoutrrr-action@v1
with:
url: ${{ secrets.NOTIFICATION_URL }}
title: "Build Failed for Release v${{ env.VERSION }}"
message: |
The build for release v${{ env.VERSION }} has failed.
Commit message: ${{ github.event.head_commit.message }}
Commit SHA: ${{ github.sha }}
- name: Notify Discord on success
if: success()
uses: containrrr/shoutrrr-action@v1
with:
url: ${{ secrets.NOTIFICATION_URL }}
title: "Build Succeeded for Release v${{ env.VERSION }}"
message: |
The build for release v${{ env.VERSION }} was successful.
Commit message: ${{ github.event.head_commit.message }}
Commit SHA: ${{ github.sha }}
The Docker image has been published.