Skip to content

Configure semantic-release for version calculation only #19

Configure semantic-release for version calculation only

Configure semantic-release for version calculation only #19

name: Version, Build, Publish, Tag, and Release
on:
push:
branches:
- main
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write
packages: write
deployments: write
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Install Dependencies
run: |
npm install -g semantic-release @semantic-release/commit-analyzer
npm list -g semantic-release
- name: Verify Installation
run: semantic-release --version
- name: Run Semantic Release
id: semantic
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
OUTPUT=$(npx semantic-release)
echo "Semantic Release Run Output:"
echo "$OUTPUT"
VERSION=$(echo "$OUTPUT" | grep -ioP '(?<=The next release version is )[0-9]+\.[0-9]+\.[0-9]+' || echo "")
if [ -n "$VERSION" ]; then
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
echo "New version: $VERSION"
# Create and push tag
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git tag -a v$VERSION -m "Release $VERSION"
git push origin v$VERSION
else
echo "No new version to release"
echo "RELEASE_VERSION=latest" >> $GITHUB_ENV
fi
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: service
file: ./service/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/${{ github.repository }}:${{ env.RELEASE_VERSION }}
ghcr.io/${{ github.repository }}:latest
outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=Tconfigd - Central daemon for distributing and managing Tratteria configurations
- name: Create GitHub Release
if: env.RELEASE_VERSION != 'latest'
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ env.RELEASE_VERSION }}
name: Release ${{ env.RELEASE_VERSION }}
body: |
Release ${{ env.RELEASE_VERSION }}
Docker images for this release:
- `ghcr.io/${{ github.repository }}:${{ env.RELEASE_VERSION }}`
For a detailed list of all changes, please refer to the automatically generated release notes below.
draft: false
prerelease: false
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}