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" token: description: 'A Gitea PAT' required: true runs: using: composite steps: - name: Checkout repo uses: actions/checkout@v4 - name: Checking if ran on the dev branch run: | if [[ "${{ github.ref }}" != refs/heads/dev ]]; then log_info $(red)ERROR$(reset_color) This can only be ran on the dev branch exit 1 fi - name: Get new version run: | last_version="$(git -c 'versionsort.suffix=-' ls-remote --tags -q --refs --sort '-v:refname' | head -n 1 | cut -d "/" -f3 || 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: Setting up release git account run: | git config user.email "release@example.com" git config user.name "Release" log_info "Overriding git repository auth with PAT" repo_url="$(git remote get-url origin)" repo_url="${repo_url#https://}" # Remove HTTPS GIT_NEW_URL="https://${GITHUB_REPOSITORY_OWNER}:${{ inputs.token }}@${repo_url}.git" git remote set-url origin "$GIT_NEW_URL" git config --local --unset http.https://${GITHUB_SERVER_URL#https://}/.extraheader - name: Pushing new version run: | log_info "Pushing new tag" git fetch git tag -a "v${NEW_VERSION}" -m "Release version ${NEW_VERSION}" git push origin "v${NEW_VERSION}" - name: Fast forwarding master branch to dev run: | log_info "Fast-forwarding master to dev" git checkout master git merge --ff-only dev git push --force-with-lease