Skip to content

Update Login

Update Login #130

name: Create tag on PR Merge
permissions: write-all
on:
pull_request:
types: [closed]
branches:
- main
jobs:
fetch-labels-and-create-tag:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
# Checkout the code
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 #Fetch all history and tags
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.x'
- name: Restore dependencies
run: dotnet restore Chirp/
- name: Build
run: dotnet build --no-restore Chirp/
- name: Install playwright
working-directory: Chirp/test/PlaywrightTests/bin/Debug/net8.0/
run: pwsh playwright.ps1 install --with-deps
- name: Test
working-directory: Chirp/
env:
authentication_github_clientId: ${{ secrets.GITHUBCLIENTID }}
authentication_github_clientSecret: ${{ secrets.GITHUBCLIENTSECRET }}
run: dotnet test --verbosity normal
# Get the latest tag from the repository
- name: Get latest tag
run: |
LATEST_TAG=$(git describe --tags --abbrev=0 || echo "v0.0.0") # Get latest tag or default to v0.0.0
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
echo "Current latest tag is $LATEST_TAG"
- name: Get PR labels
run: |
PR_LABELS="${{ join(github.event.pull_request.labels.*.name, ',') }}"
echo "PR_LABELS=$PR_LABELS" >> $GITHUB_ENV
echo "Labels fetched: $PR_LABELS"
# Determine the next version based on PR labels
- name: Calculate next version
run: |
# Initizalise skip release
echo "SKIP_RELEASE=false" >> $GITHUB_ENV
# Check if "workflow" label is present and skip if so
if echo "$PR_LABELS" | grep -E -q "(^|,)workflow(,|$)"; then
echo "Workflow label detected. Skipping release process."
echo "SKIP_RELEASE=true" >> $GITHUB_ENV
exit 0
fi
# Extract major, minor, patch from the latest tag (strip leading 'v')
VERSION=${LATEST_TAG#v}
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
# Check which label is present and increment the version accordingly
if echo "$PR_LABELS" | grep -E -q "(^|,)breaking(,|$)"; then
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
# feature
elif echo "$PR_LABELS" | grep -E -q "(^|,)feature(,|$)"; then
MINOR=$((MINOR + 1))
PATCH=0
# bug
elif echo "$PR_LABELS" | grep -E -q "(^|,)bug(,|$)"; then
PATCH=$((PATCH + 1))
else
echo "No release related label detected. Skipping release process."
echo "SKIP_RELEASE=true" >> $GITHUB_ENV
exit 0
fi
# Construct the new version
NEW_VERSION="v$MAJOR.$MINOR.$PATCH"
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
echo "Calculated new version: $NEW_VERSION"
- name: Cancel Workflow
if: env.SKIP_RELEASE == 'true'
run: exit 78
# Create a new Git tag with the calculated version
- name: Create Git Tag
if: env.SKIP_RELEASE != 'true'
run: |
git config --local user.name "GitHub Actions"
git config --local user.email "actions@github.com"
git tag $NEW_VERSION
git push origin $NEW_VERSION