Skip to content

Florent228 is testing out GitHub Actions #20

Florent228 is testing out GitHub Actions

Florent228 is testing out GitHub Actions #20

Workflow file for this run

name: CI/CD Workflow for Node.js Project
run-name: ${{ github.actor }} is testing out GitHub Actions
permissions: write-all
on:
push:
branches: [dev]
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
- name: Cache npm
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
build-and-push-docker:
needs: build-and-test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Log in to GitHub Container Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Build Docker image
run: docker build -t kawa_customer:latest .
- name: Push Docker image
run: |
lower_repo_owner=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
docker tag kawa_customer:latest ghcr.io/${lower_repo_owner}/kawa_customer:latest
docker push ghcr.io/${lower_repo_owner}/kawa_customer:latest
- name: Clean up Docker images
run: |
if docker images | grep -q 'kawa_customer'; then
docker rmi kawa_customer:latest
else
echo "Image kawa_customer:latest not found. Skipping cleanup."
fi
- name: Display Docker image path
run: echo "ghcr.io/${{ github.repository_owner }}/kawa_customer:latest"
merge-to-main:
needs: build-and-push-docker
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/dev'
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: dev
- name: Configure git
run: |
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
- name: Merge dev into main
run: |
git checkout main
git merge dev --no-ff --allow-unrelated-histories --commit -m "Fusion automatisée de dev en main"