π Merge pull request #16 from jyje/develop #1
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: | |
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: | |
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 | |
run: | | |
# Check if the tag is in the correct format | |
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 | |
# Check if the tag already exists | |
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: 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 }} |