Skip to content

Commit

Permalink
Ajout github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
bepi-octo committed Oct 16, 2024
1 parent 66178cc commit 562df57
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Build and deploy

on:
push:
branches:
- main
- staging
- dev
- add_github_actions

env:
IMAGE_NAME: ghcr.io/${{ github.repository }}/frontend
IMAGE_TAG: ${{ github.sha }}

jobs:
build-and-push:
if: contains(fromJson('["main", "staging", "dev", "add_github_actions"]'), github.ref_name)
name: Build and push from ${{ github.ref_name }}/${{ github.sha }}
outputs:
commit_title: ${{ steps.get_head_commit_title.outputs.title }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- id: get_head_commit_title
run: echo "title=$(git log --format=%B -n 1 HEAD | head -n 1)" >> $GITHUB_OUTPUT

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }},${{ env.IMAGE_NAME }}:${{github.ref_name}}-latest
cache-from: type=gha
cache-to: type=gha,mode=max

deploy-dev:
name: Deploy from ${{ github.ref_name }}/${{ github.sha }}
runs-on: ubuntu-latest
needs: build-and-push
if: github.ref_name == 'dev'
steps:
- name: Trigger dev deployment
run: |
RESPONSE="$(curl --request POST \
--form token=${{ secrets.GITLAB_CI_TOKEN }} \
--form ref=main \
--form 'variables[pipeline_name]=${{ github.event.repository.name }} - ${{ needs.build-and-push.outputs.commit_title }}' \
--form 'variables[frontend_docker_image_tag]=${{ env.IMAGE_TAG }}' \
--form 'variables[application_to_deploy]=france-services' \
--form 'variables[deployment_environment]=dev' \
'https://gitlab.com/api/v4/projects/58117805/trigger/pipeline')"
if echo "$RESPONSE" | grep -q '"status":"created"'; then
echo $RESPONSE
else
echo $RESPONSE
exit 1
fi

0 comments on commit 562df57

Please sign in to comment.