Create new tag on repository dispatch #5
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: Create new tag on repository dispatch | |
on: | |
workflow_dispatch: | |
repository_dispatch: | |
types: [sveltia-cms-publish] # Specify your custom event type here | |
jobs: | |
create_tag: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
with: | |
ref: ${{ vars.CMS_DISPATCH_REF }} | |
- name: Get current date | |
id: date | |
run: echo "DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV | |
- name: Determine tag sequence number | |
id: tag_number | |
run: | | |
BRANCH_NAME=${{ vars.CMS_DISPATCH_REF }} | |
DATE=$(date +'%Y%m%d') | |
TAG_PREFIX="${BRANCH_NAME}-${DATE}" | |
EXISTING_TAGS=$(git tag --list "${TAG_PREFIX}-*") | |
if [ -z "$EXISTING_TAGS" ]; then | |
SEQUENCE=1 | |
else | |
SEQUENCE=$(echo "$EXISTING_TAGS" | awk -F '-' '{print $NF}' | sort -n | tail -1) | |
SEQUENCE=$((SEQUENCE + 1)) | |
fi | |
echo "TAG_NAME=${TAG_PREFIX}-${SEQUENCE}" >> $GITHUB_ENV | |
- name: Create a new tag | |
run: | | |
git tag ${{ env.TAG_NAME }} | |
git push origin ${{ env.TAG_NAME }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.API_TOKEN_GITHUB }} |