Create MCPACK and release #7
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: Zip and Add to Release | |
on: | |
push: | |
tags: | |
- '*' | |
workflow_dispatch: # Allows manual triggering | |
jobs: | |
zip-and-release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v3 | |
- name: Set up Git user | |
run: | | |
git config --global user.name "github-actions" | |
git config --global user.email "[email protected]" | |
- name: Get the latest tag | |
id: get_tag | |
run: | | |
# Fetch tags from remote to ensure we get the latest pushed tag | |
git fetch --tags | |
# Get the most recent tag based on lexicographical order | |
TAG=$(git tag -l | sort -V | tail -n 1) | |
# If no tags found, fallback to a default tag | |
if [ -z "$TAG" ]; then | |
TAG="v0.0.0" | |
fi | |
echo "Using latest tag: $TAG" | |
echo "TAG=$TAG" >> $GITHUB_ENV | |
- name: Zip the repository | |
run: | | |
zip -r $GITHUB_ENV.TAG.zip . | |
- name: Create a release if it doesn't exist | |
id: create_release | |
run: | | |
# Check if a release exists for the latest tag | |
RELEASE_EXISTS=$(gh release view $TAG --json tagName --jq ".tagName" || echo "false") | |
if [ "$RELEASE_EXISTS" == "false" ]; then | |
echo "Creating release for tag: $TAG" | |
gh release create $TAG $GITHUB_ENV.TAG.zip --title "Release $TAG" --notes "Release notes for $TAG" | |
else | |
echo "Release already exists for tag: $TAG" | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Upload the zip file as a release asset | |
uses: softprops/action-gh-release@v1 | |
with: | |
files: $GITHUB_ENV.TAG.zip | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |