commit 91ebdda34674a917a1d9c5ca0f7f39da36266c68 Author: Skydust Date: Wed Dec 25 15:46:40 2024 +0100 First commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/README.md b/README.md new file mode 100644 index 0000000..685c6af --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# create-release + diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..e107bb6 --- /dev/null +++ b/action.yml @@ -0,0 +1,59 @@ +name: Create Semver Release +description: Uses tags and semver type to push a tag on the latest commit +author: Skydust + +# Define your inputs here. +inputs: + semver: + type: choice + description: Choose the semver + options: + - "Major - Incompatible API changes" + - "Minor - Adding functionality in a backward compatible manner" + - "Patch - Backward compatible bug fixes" + +runs: + using: composite + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Include full history with tags + - name: Get new version + run: | + last_version="$(git describe --tags --match "v*" --abbrev=0 || echo "")" + if [[ -z "$last_version" ]]; then + last_version="v0.0.0" + fi + last_version="${last_version:1}" + log_info "Last version: ${last_version}" + + # Split the version into components + IFS='.' read -r major minor patch <<< "${last_version%%-*}" + + # Increment the appropriate part of the version + case "${{ inputs.semver }}" in + "Major"*) NEW_VERSION="$((major + 1)).0.0" + ;; + "Minor"*) NEW_VERSION="$major.$((minor + 1)).0" + ;; + "Patch"*) NEW_VERSION="$major.$minor.$((patch + 1))" + ;; + esac + + log_info "Requested ${{ inputs.semver }} update" + log_info "New version: ${NEW_VERSION}" + + echo NEW_VERSION=${NEW_VERSION} >> $GITEA_ENV + - name: Pushing new version + run: | + git config user.email "release@example.com" + git config user.name "Release" + + original_url="$(git remote get-url origin)" + repo_url="${original_url#https://}" # Remove HTTPS + new_url="https://x-access-token:${{ secrets.CI_GIT_WRITE_TOKEN }}@$repo_url" + git remote set-url origin "$new_url" + + git fetch + git tag -a "v${NEW_VERSION}" -m "Release version ${NEW_VERSION}" + git push origin "v${NEW_VERSION}"