π Merge pull request #38 from jyje/version/10.3.0 #23
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-main | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
init: | |
name: π§ Inintialize | |
runs-on: ubuntu-latest | |
outputs: | |
step_init: ${{ steps.check_flag.outputs.step_init }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Check for --no-ci flag in commit message | |
id: check_flag | |
run: | | |
echo "Checking commit message for --no-ci flag..." | |
if echo "${{ github.event.head_commit.message }}" | grep -- '--no-ci'; then | |
echo "step_init=false" >> $GITHUB_OUTPUT | |
else | |
echo "step_init=true" >> $GITHUB_OUTPUT | |
fi | |
build-and-release: | |
name: π Build and Release | |
needs: init | |
if: ${{ needs.init.outputs.step_init == 'true' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Extract tag | |
run: | | |
echo "image_version=v$(cat requirements.txt | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+')" >> $GITHUB_ENV | |
- name: Check tag format | |
run: | | |
export TAG_NAME="${{ env.image_version }}" | |
if ! [[ "$TAG_NAME" =~ ^v[0-9]+\.[0-9]+(\.[0-9]+)?$ ]]; then | |
echo "Tag $TAG_NAME does not meet the required format 'vX.Y.Z'." | |
exit 1 | |
fi | |
- name: Check a tag from list | |
run: | | |
git fetch --unshallow --tags | |
export TAG_NAME="${{ env.image_version }}" | |
export TAG_EXISTS=$(git tag --list $TAG_NAME) | |
if [ -n "$TAG_EXISTS" ]; then | |
echo "Tag $TAG_NAME already exists." | |
exit 1 | |
fi | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build/Publish as GitHub Package | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ./Dockerfile | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: | | |
ghcr.io/${{ github.repository }}:latest | |
ghcr.io/${{ github.repository }}:${{ env.image_version }} | |
- name: Set tag and push in Github | |
run: | | |
# Set Git identity | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
# Check if the tag already exists | |
TAG_EXISTS=$(git tag --list ${{ env.image_version }}) | |
if [ -n "$TAG_EXISTS" ]; then | |
echo "Tag ${{ env.image_version }} already exists." | |
exit 0 | |
fi | |
# Create and push the new tag | |
git tag ${{ env.image_version }} | |
git push origin ${{ env.image_version }} | |
- name: Create Release | |
if: success() | |
uses: ncipollo/release-action@v1 | |
with: | |
tag: ${{ env.image_version }} | |
name: Release ${{ env.image_version }} | |
token: ${{ secrets.GITHUB_TOKEN }} |