Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pushing tags doesn't work #11

Open
sdruskat opened this issue Nov 14, 2024 · 2 comments
Open

Pushing tags doesn't work #11

sdruskat opened this issue Nov 14, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@sdruskat
Copy link
Contributor

Copying the GitHub template and changing it to run on pushed tags leads to a failing workflow:

on:
  push:
    tags:
      - "**"

This is because the checkout actions (or rather, git) checks out into detached HEAD state.

In these cases, a new branch must be created from the detached HEAD before copying it, otherwise you run into fatal: cannot copy the current branch while not on any.

We need to reflect this in the template and the docs website (docs.smp) as this is a very common case.

@sdruskat sdruskat added the bug Something isn't working label Nov 14, 2024
@sdruskat
Copy link
Contributor Author

Action log:

Run # Cache current branch for PR close job
  # Cache current branch for PR close job
  git branch --show-current > .hermes/curate/target_branch
  
  # Shorten the SHA for the PR title
  SHORT_SHA=$(echo "$GITHUB_SHA" | cut -c -8)
  echo "SHORT_SHA=$SHORT_SHA" >> "$GITHUB_ENV"
  
  # Create a curation branch
  git branch -c "hermes/curate-$SHORT_SHA"                                   <--- Fails!
  git push origin "hermes/curate-$SHORT_SHA"
  
  # Explicitly add to-be-curated metadata (which is ignored via .gitignore!)
  git add -f .hermes/curate
  shell: /usr/bin/bash -e {0}
  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.10.15/x64
    PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.10.15/x64/lib/pkgconfig
    Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.10.15/x64
    Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.10.15/x64
    Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.10.15/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.10.15/x64/lib
fatal: cannot copy the current branch while not on any
Error: Process completed with exit code 128.

@sdruskat
Copy link
Contributor Author

sdruskat commented Nov 14, 2024

One workaround could be something like

# If HEAD is detached (e.g., when a tag has been checked out),
# switch to new temporary branch hermes/tmp/<current ref>,
# and push that to origin
if [ $(git branch --show-current | wc -l) -eq "0" ]; then
  HERMES_TMP_BRANCH=hermes/tmp-$(git rev-parse --short HEAD)
  git switch -c $HERMES_TMP_BRANCH
  git push -u origin $HERMES_TMP_BRANCH
fi

Then, the branch should also be deleted in hermes-curate and hermes-cleanup:

for BRANCH in $(git ls-remote origin 'refs/heads/hermes/curate-*' | cut -f2 | cut -d'/' -f'3-'); do
  git push origin --delete "$BRANCH"
done
for BRANCH in $(git ls-remote origin 'refs/heads/$HERMES_TMP_BRANCH' | cut -f2 | cut -d'/' -f'3-'); do   <---
  git push origin --delete "$BRANCH"                                                                     <---
done                                                                                                     <---

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant