Test Ci/CD #2
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/CD Pipeline | |
on: | |
push: | |
branches: | |
- main | |
- dev | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout des Codes | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# Log in to Docker Hub | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
# Set Docker Tag basierend auf dem Branch | |
- name: Set Docker Tag | |
run: | | |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then | |
echo "IMAGE_TAG=latest" >> $GITHUB_ENV | |
elif [[ "${{ github.ref }}" == "refs/heads/dev" ]]; then | |
echo "IMAGE_TAG=dev" >> $GITHUB_ENV | |
fi | |
# Build Docker Image | |
- name: Build Docker Image | |
run: | | |
docker build -t ${{ secrets.DOCKER_USERNAME }}/brother_ql_app:${{ env.IMAGE_TAG }} . | |
# Push Docker Image to Docker Hub | |
- name: Push Docker Image | |
run: | | |
docker push ${{ secrets.DOCKER_USERNAME }}/brother_ql_app:${{ env.IMAGE_TAG }} | |
release: | |
if: github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout des Codes | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# Git konfigurieren | |
- name: Configure Git | |
run: | | |
git config --global user.email "ci@github-actions.com" | |
git config --global user.name "GitHub Actions CI" | |
# Git-Version setzen und neuen Release-Tag erstellen | |
- name: Set up Git and Release Version | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git fetch --tags | |
# Überprüfen, ob ein Tag existiert | |
VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0") | |
# Falls keine Tags existieren, starte mit 1.0.0 | |
if [[ "$VERSION" == "0.0.0" ]]; then | |
NEW_VERSION="1.0.0" | |
else | |
NEW_VERSION=$(echo $VERSION | awk -F. -v OFS=. '{$NF++; print}') | |
fi | |
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV | |
# Neuen Tag erstellen und pushen. | |
git tag -a $NEW_VERSION -m "Release $NEW_VERSION" | |
git push origin $NEW_VERSION | |
# GitHub Release erstellen | |
- name: Create GitHub Release | |
uses: actions/create-release@v1 | |
with: | |
tag_name: ${{ env.NEW_VERSION }} | |
release_name: "Release ${{ env.NEW_VERSION }}" | |
body: "Automated release of version ${{ env.NEW_VERSION }}." | |
draft: false | |
prerelease: false | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |