Try to update version with commit message #58
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: CI Docker and Helm | |
on: | |
push: | |
branches: | |
- workflow/api-improve | |
env: | |
IMAGE_NAME: amelieloulou/transform-and-deliver-assets | |
CHART_PATH: ./opensource | |
jobs: | |
determine-version: | |
runs-on: ubuntu-latest | |
outputs: | |
new_version: ${{ steps.set_output.outputs.new_version }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Get the latest tag | |
id: get_latest_tag | |
run: echo "::set-output name=tag::$(git describe --tags --abbrev=0)" | |
- name: Determine next version | |
id: set_output | |
run: | | |
latest_tag=${{ steps.get_latest_tag.outputs.tag }} | |
echo "Latest tag: $latest_tag" | |
# Extract the major, minor, and patch numbers from the tag | |
IFS='.' read -r -a version_parts <<< "${latest_tag#v}" | |
major=${version_parts[0]} | |
minor=${version_parts[1]} | |
patch=${version_parts[2]} | |
# Determine the type of version bump | |
if [[ ${{ github.event.head_commit.message }} == *"major"* ]]; then | |
major=$((major + 1)) | |
minor=0 | |
patch=0 | |
elif [[ ${{ github.event.head_commit.message }} == *"minor"* ]]; then | |
minor=$((minor + 1)) | |
patch=0 | |
else | |
patch=$((patch + 1)) | |
fi | |
new_version="v$major.$minor.$patch" | |
echo "New version: $new_version" | |
echo "::set-output name=new_version::$new_version" | |
build-and-push-docker-api: | |
runs-on: ubuntu-latest | |
needs: determine-version | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Cache npm dependencies for API | |
uses: actions/cache@v3 | |
with: | |
path: src/api/node_modules | |
key: ${{ runner.os }}-api-node-modules-${{ hashFiles('src/api/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-api-node-modules- | |
- name: Install npm dependencies for API | |
working-directory: src/api | |
run: npm install | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
with: | |
install: true | |
- name: Cache Docker layers | |
uses: actions/cache@v3 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and push Docker image API | |
run: | | |
docker buildx build --platform linux/amd64,linux/arm64 --push -t ${{ env.IMAGE_NAME }}:api-${{ needs.determine-version.outputs.new_version }} --cache-from=type=local,src=/tmp/.buildx-cache --cache-to=type=local,dest=/tmp/.buildx-cache,mode=max ./src/api | |
build-and-push-docker-job: | |
runs-on: ubuntu-latest | |
needs: determine-version | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
with: | |
install: true | |
- name: Cache Docker layers | |
uses: actions/cache@v3 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and push Docker image Job | |
run: | | |
docker buildx build --platform linux/amd64,linux/arm64 --push -t ${{ env.IMAGE_NAME }}:job-${{ needs.determine-version.outputs.new_version }} --cache-from=type=local,src=/tmp/.buildx-cache --cache-to=type=local,dest=/tmp/.buildx-cache,mode=max ./src | |
publish-helm-chart: | |
runs-on: ubuntu-latest | |
needs: | |
- build-and-push-docker-api | |
- build-and-push-docker-job | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Install Helm | |
uses: azure/setup-helm@v3 | |
with: | |
version: v3.11.1 | |
- name: Package Helm chart | |
run: | | |
helm package opensource | |
- name: Push Helm chart to Docker Hub | |
run: | | |
helm push $(ls *.tgz) oci://registry-1.docker.io/amelieloulou |