diff --git a/.gitea/workflows/build_and_puplish.yml b/.gitea/workflows/build_and_puplish.yml index ef082e7..1ccdcba 100644 --- a/.gitea/workflows/build_and_puplish.yml +++ b/.gitea/workflows/build_and_puplish.yml @@ -36,8 +36,23 @@ jobs: git config user.email "${{ vars.EMAIL_GIT }}" git add package.json git commit -m "Update version to ${{ github.ref_name }}" || echo "No changes to commit." - BRANCH=$(git for-each-ref --format='%(refname:short)' --contains HEAD refs/remotes/origin | head -n1) - BRANCH=${BRANCH#origin/} + + # Get current branch; if detached, resolve to a remote branch that contains this commit + BRANCH="$(git rev-parse --abbrev-ref HEAD)" + if [[ "$BRANCH" == "HEAD" || -z "$BRANCH" ]]; then + # If target_commitish is a branch, use it; if it’s a SHA, find a branch that contains it + CANDIDATE='${{ github.event.release.target_commitish }}' + if [[ "$CANDIDATE" =~ ^[0-9a-f]{40}$ ]]; then + BRANCH="$(git branch -r --contains "$GITHUB_SHA" | sed -n 's|.*origin/||p' | head -n1)" + else + BRANCH="$CANDIDATE" + fi + fi + + if [[ -z "$BRANCH" ]]; then + echo "Could not determine branch for push."; git branch -a; exit 1 + fi + git push origin HEAD:refs/heads/$BRANCH - name: Publish to Visual Studio Marketplace (Pre-Release) if: ${{ github.event.release.prerelease }}