Have a different folder name on git than on local // Execute a github action before pulling

Viewed 97

I've been struggling with this for way too long now, I can't find a way to achieve a really simple thing (at least that's what I thought).

My use case is this :

I'm a Unity dev, and I'm working on multiple UPM packages that can be installed by anyone using Unity's package manager. In a package, you can have a folder named (exactly) "Samples~", which then can be imported in a project when you downloaded this package using an UI button on the package manager :

UPM

The thing is, all folders named with a "~" at the end are hidden in the project view.

So, basically, what I need is : on my computer, the folder name should be "Samples", BUT on the release on git, the folder should be named "Samples~". Atm, using a github action I am able to rename Samples to Samples~ after every push, which is great ! But I cannot do the exact opposite, because there is no "pull" event for github actions...

Here is my script that works fine :

name: Rename tilded folders
on:
  push:
    branches:
    - master

jobs:
  rename_samples:
    name: Create branches
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - run: |
            git checkout master
            git config --global user.name 'github-bot'
            git config --global user.email 'github-bot@users.noreply.github.com'
            if [[ -d "Samples" ]]; then
              git mv Samples Samples~
              rm -f Samples.meta
              git commit -am "rename: Samples => Samples~"
              git push origin master
            else
              echo "${i}Samples does not exist"
            fi
            if [[ -d "Documentation" ]]; then
              git mv Documentation Documentation~
              rm -f Documentation.meta
              git commit -am "rename: Documentation => Documentation~"
              git push origin master
            else
              echo "${i}Documentation does not exist"
            fi

Is there an easy way to achieve what I need (basically, have a different name in the git repo, or even better only in the release) ?

1 Answers

That's not something github actions handle. See events.

If I was to continue with your line of reasoning, I would probably suggest you need something in your IDE that treats the folders as if they don't have a tilde.

Or guggest to use a git hook that renames the folders once they have been downloaded and reverts the names before committing.

Those solutions are fine, but very brittle and involved.

IMO, you should focus on what happens at release time and rather than renaming the file between pushes and commits, I would recommend having a release branch which contains the code that will eventually be released.

This means in your workflow you have above, change this line:

git push origin master

to

git push origin release/next

Instead of modifying the code in master, now you simply push everything to your release branch, and when you are ready to create a release, you use that branch.

HTH.

Related