Files
ButlerBot/.gitea/workflows/build-and-publish.yml
Jack 2807d662d6
Some checks failed
Build and Publish Docker Image / build_and_push (push) Failing after 9s
Fix retrieval of version number from package.json
2024-09-16 10:08:06 +00:00

73 lines
2.3 KiB
YAML

name: Build and Publish Docker Image
on:
push:
branches:
- main
- develop
- feature/devops
jobs:
build_and_push:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 'lts/Iron'
- name: Log in to Docker Registry
uses: docker/login-action@v3
with:
username: ${{ secrets.USERNAME }}
password: ${{ secrets.TOKEN }}
registry: git.3t.network
- name: Set Docker Image Tags
id: set_tags
run: |
GIT_HASH=${{env.GITHUB_SHA}}
IMAGE_NAME=git.3t.network/3t.network/ButlerBot:${GIT_HASH:0:7}
# Initialize the TAGS variable with the image name and hash
TAGS=$IMAGE_NAME
# Calculate additional tags based on branch
if [ "${{ gitea.ref_name }}" = 'main' ]; then
VERSION=$(node -p -e "require('./package.json').version")
TAGS+=",git.3t.network/3t.network/ButlerBot:latest"
TAGS+=",git.3t.network/3t.network/ButlerBot:$VERSION"
elif [ "${{ gitea.ref_name }}" = 'develop' ]; then
VERSION=$(node -p -e "require('./package.json').version)-dev
TAGS+=",git.3t.network/3t.network/ButlerBot:dev"
TAGS+=",git.3t.network/3t.network/ButlerBot:$VERSION"
fi
# Write the tags to the GITHUB_OUTPUT file to set the output
echo "image_tags=$TAGS" >> $GITHUB_OUTPUT
- name: Build and Push Docker Image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.set_tags.outputs.image_tags }}
# - name: Set Portainer Webhook URL
# run: |
# if [[ "${{ gitea.ref_name }}" == "main" ]]; then
# echo "PORTAINER_WEBHOOK_URL=${{ secrets.PORTAINER_WEBHOOK_URL_MAIN }}" >> $GITHUB_ENV
# elif [[ "${{ gitea.ref_name }}" == "develop" ]]; then
# echo "PORTAINER_WEBHOOK_URL=${{ secrets.PORTAINER_WEBHOOK_URL_DEV }}" >> $GITHUB_ENV
# fi
# - name: Trigger Portainer Webhook
# run: |
# curl -X POST --silent --fail "$PORTAINER_WEBHOOK_URL"
# env:
# PORTAINER_WEBHOOK_URL: ${{ env.PORTAINER_WEBHOOK_URL }}