Compare commits
18 Commits
5867cfc3e1
...
staging
Author | SHA1 | Date | |
---|---|---|---|
570b5abfa0 | |||
8f938f999e | |||
2249d1a776 | |||
37de21f06b | |||
b9d5ade0f1 | |||
921b4a9664 | |||
0e9555e3f7 | |||
19c7aaaca1 | |||
068c67d0d9 | |||
4c6635f989 | |||
98080df509 | |||
286f72eac7 | |||
d49977815d | |||
b012693c21 | |||
e385eb94f4 | |||
285ff89cb0 | |||
fe45d901e4 | |||
ba6e201adc |
@@ -2,16 +2,9 @@ name: Gitea CI/CD
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
#push:
|
||||
#branches: [ "development", "main", "staging"]
|
||||
#tags: [ "v*.*.*" ]
|
||||
pull_request:
|
||||
#branches: [ "development", "main", "staging" ]
|
||||
push:
|
||||
branches: [ "development", "main", "staging" ]
|
||||
tags: [ "v*.*.*" ]
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
packages: write
|
||||
|
||||
env:
|
||||
DOTNET_VERSION: '8.0.x'
|
||||
@@ -19,8 +12,12 @@ env:
|
||||
REGISTRY_URL: git.triggermeelmo.com
|
||||
DOCKER_PLATFORMS: 'linux/amd64,linux/arm64'
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build-and-test:
|
||||
dotnet-build-and-test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
@@ -46,13 +43,14 @@ jobs:
|
||||
|
||||
set-tag:
|
||||
name: Set Tag Name
|
||||
needs: [dotnet-build-and-test]
|
||||
#if: ${{ !failure() && !cancelled() && github.event_name != 'pull_request' }}
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
tag_name: ${{ steps.set_tag.outputs.tag_name }}
|
||||
should_tag: ${{ steps.set_tag.outputs.should_tag }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Determine next semantic version tag
|
||||
id: set_tag
|
||||
@@ -74,20 +72,33 @@ jobs:
|
||||
major=$((major + 1))
|
||||
minor=0
|
||||
patch=0
|
||||
new_tag="v${major}.${minor}.${patch}"
|
||||
echo "tag_name=${new_tag}" >> $GITHUB_OUTPUT
|
||||
echo "should_tag=true" >> $GITHUB_OUTPUT
|
||||
echo "Creating new major version tag: ${new_tag}"
|
||||
|
||||
elif [[ "${GITHUB_REF}" == "refs/heads/development" ]]; then
|
||||
minor=$((minor + 1))
|
||||
patch=0
|
||||
new_tag="v${major}.${minor}.${patch}"
|
||||
echo "tag_name=${new_tag}" >> $GITHUB_OUTPUT
|
||||
echo "should_tag=true" >> $GITHUB_OUTPUT
|
||||
echo "Creating new minor version tag: ${new_tag}"
|
||||
|
||||
elif [[ "${GITHUB_REF}" == "refs/heads/staging" ]]; then
|
||||
patch=$((patch + 1))
|
||||
new_tag="v${major}.${minor}.${patch}"
|
||||
echo "tag_name=${new_tag}" >> $GITHUB_OUTPUT
|
||||
echo "should_tag=true" >> $GITHUB_OUTPUT
|
||||
echo "Creating new patch version tag: ${new_tag}"
|
||||
fi
|
||||
|
||||
new_tag="v${major}.${minor}.${patch}"
|
||||
echo "Creating new version tag: ${new_tag}"
|
||||
echo "tag_name=${new_tag}" >> $GITHUB_OUTPUT
|
||||
|
||||
docker-build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [build-and-test, set-tag]
|
||||
needs: [dotnet-build-and-test, set-tag]
|
||||
if: |
|
||||
needs.set-tag.outputs.should_tag == 'true' &&
|
||||
github.event_name != 'pull_request'
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
@@ -111,37 +122,25 @@ jobs:
|
||||
|
||||
tag:
|
||||
name: Create Tag
|
||||
needs: [docker-build-and-push]
|
||||
needs: [docker-build-and-push, set-tag]
|
||||
if: |
|
||||
needs.set-tag.outputs.should_tag == 'true' &&
|
||||
github.event_name != 'pull_request'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Check if tag already exists
|
||||
id: check_tag
|
||||
- name: Set up Git user
|
||||
run: |
|
||||
git fetch --tags
|
||||
if git rev-parse "${{ needs.set-tag.outputs.tag_name }}" >/dev/null 2>&1; then
|
||||
echo "Tag ${{ needs.set-tag.outputs.tag_name }} already exists!"
|
||||
echo "exists=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "Tag ${{ needs.set-tag.outputs.tag_name }} does not exist"
|
||||
echo "exists=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Create and push tag
|
||||
if: steps.check_tag.outputs.exists == 'false'
|
||||
run: |
|
||||
echo "Creating new tag: ${{ needs.set-tag.outputs.tag_name }}"
|
||||
git config user.name "GitHub Actions"
|
||||
git config user.email "actions@github.com"
|
||||
git tag ${{ needs.set-tag.outputs.tag_name }}
|
||||
git push -u origin ${{ needs.set-tag.outputs.tag_name }}
|
||||
echo "Tag created and pushed successfully"
|
||||
|
||||
- name: Skip tag creation
|
||||
if: steps.check_tag.outputs.exists == 'true'
|
||||
- name: Create and push tag
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
echo "Skipping tag creation - ${{ needs.set-tag.outputs.tag_name }} already exists"
|
||||
echo "Creating new tag: ${{ needs.set-tag.outputs.tag_name }}"
|
||||
git tag ${{ needs.set-tag.outputs.tag_name }}
|
||||
git push origin ${{ needs.set-tag.outputs.tag_name }}
|
Reference in New Issue
Block a user