update3 #59
Workflow file for this run
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: build_service_sso | |
on: | |
pull_request: | |
types: [closed] | |
branches: | |
- main | |
paths: | |
- "services/sso/**" | |
permissions: | |
contents: write | |
jobs: | |
build_service_sso: | |
runs-on: ubuntu-latest | |
if: contains(github.event.pull_request.labels.*.name, 'tag/major') || contains(github.event.pull_request.labels.*.name, 'tag/minor') || contains(github.event.pull_request.labels.*.name, 'tag/patch') | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
fetch-tags: true | |
- name: Use Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "18" | |
- name: Determine Semantic Version | |
id: version | |
run: | | |
current_version=$(git tag --sort=-v:refname | grep '^service_sso/[0-9]\+' | head -n1) | |
echo "Current version 1: $current_version" | |
if [ -z "$current_version" ]; then | |
current_version="service_sso/0.0.0" | |
fi | |
echo "Current version 2: $current_version" | |
# Extract major, minor, and patch components safely | |
major=$(echo $current_version | cut -d'/' -f2 | cut -d'.' -f1 | sed 's/v//') | |
minor=$(echo $current_version | cut -d'.' -f2) | |
patch=$(echo $current_version | cut -d'.' -f3) | |
echo "Current version: $current_version" | |
echo "Major: $major" | |
echo "Minor: $minor" | |
echo "Patch: $patch" | |
# Handle empty values | |
if [ -z "$major" ]; then major=0; fi | |
if [ -z "$minor" ]; then minor=0; fi | |
if [ -z "$patch" ]; then patch=0; fi | |
# Labels | |
labels=${{ toJson(github.event.pull_request.labels.*.name) }} | |
echo "Labels: $labels" | |
# Increment the version based on labels using GitHub Actions event context | |
if [[ "$labels" == *"tag/major"* ]]; then | |
next_version="$((major + 1)).0.0" | |
if [[ "$labels" == *"tag/minor"* ]]; then | |
next_version="$major.$((minor + 1)).0" | |
else | |
next_version="$major.$minor.$((patch + 1))" | |
fi | |
# Output the next version | |
echo "Next version: $next_version" | |
echo "::set-output name=version::$next_version" | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v4 | |
with: | |
context: services/sso | |
push: true | |
tags: itacademybcn/service_sso:v${{ steps.version.outputs.version }} | |
- name: Tag and Push Git Tag | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git config --local user.name "github-actions[bot]" | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git remote set-url origin "https://${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" | |
# Create and push the tag | |
git tag -a "service_sso/${{ steps.version.outputs.version }}" -m "service_sso/${{ steps.version.outputs.version }}" | |
git push origin "service_sso/${{ steps.version.outputs.version }}" |