Skip to content

Commit

Permalink
Merge pull request #1 from kickmaker/cd/deploy-new-release-in-gitlab-…
Browse files Browse the repository at this point in the history
…container-registry

cd: deploy: build docker image n gitlab container registry on new release creation
Signed-off-by: Romain Pelletant <[email protected]>
  • Loading branch information
RomainPelletant authored and Romain Pelletant committed May 3, 2024
2 parents 04e24e0 + 4532c60 commit 14281e5
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/check-new-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Nightly sync latest release from upstream

on:
push

jobs:
sync:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Sync latest release
run: |
# Récupérer la dernière release du repository d'origine
LATEST_RELEASE=$(curl -s -H "Authorization: token ${{ secrets.GH_TOKEN }}" "https://api.github.com/repos/nexB/scancode-toolkit/releases/latest")
# Extraire les informations de la dernière release
release_name=$(echo "$LATEST_RELEASE" | jq -r '.name')
release_tag=$(echo "$LATEST_RELEASE" | jq -r '.tag_name')
release_body=$(echo "$LATEST_RELEASE" | jq -r '.body')
# Récupérer la dernière release du repository d'origine
CURRENT_LATEST_RELEASE=$(curl -s -H "Authorization: token ${{ secrets.GH_TOKEN }}" "https://api.github.com/repos/kickmaker/scancode-toolkit/releases/latest")
current_release_tag=$(echo "$CURRENT_LATEST_RELEASE" | jq -r '.tag_name')
echo $release_tag
echo $current_release_tag
# Check if the latest upstream release tag is different from the current fork release tag
if [ "$release_tag" != "$current_release_tag" ]; then
# Create the latest release in the fork repository
curl -X POST \
-H "Authorization: token ${{ secrets.GH_TOKEN }}" \
-H "Content-Type: application/json" \
https://api.github.com/repos/kickmaker/scancode-toolkit/releases \
-d '{"tag_name": \"$release_tag\", "name": "$release_name", "body": "$release_body"}'
else
echo "Latest release tag is the same as the current release tag. Skipping release creation."
fi
27 changes: 27 additions & 0 deletions .github/workflows/push-docker-registry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build and push docker image on new release creation

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Login to gitLab container registry
run: echo "${{ secrets.GITLAB_TOKEN }}" | docker login -u ${{ secrets.GITLAB_USERNAME }} --password-stdin ${{ secrets.GITLAB_REGISTRY_URL }}

- name: Build and push docker image
run: |
docker build -t ${{ secrets.GITLAB_REGISTRY_URL }}/$IMAGE_NAME:${{ github.event.release.tag_name }} .
docker push ${{ secrets.GITLAB_REGISTRY_URL }}/$IMAGE_NAME:${{ github.event.release.tag_name }}
env:
GITLAB_REGISTRY_URL: ${{ secrets.GITLAB_REGISTRY_URL }}
IMAGE_NAME: scancode-toolkit
TAG: ${{ github.event.release.tag_name }}
GITLAB_USERNAME: ${{ secrets.GITLAB_USERNAME }}
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}

0 comments on commit 14281e5

Please sign in to comment.