Create directories only when release is created

Hi GitHub Community!

I’m starting my journey with GitHub Actions and I was wondering if the following is possible.

In my application I am trying to remove folders that are empty and are only needed when a copy of the app goes to somebody’s server. I don’t want to keep them in a repo because they’re empty but in my staging/dev environment I do have files there for testing the app.

I would like the action to add those empty folders to the release *.zip files. Is that possible?

I started with:

name: CI

on:
  release:
    types: [ created ]
    branches: [ master ]

  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Run the build php script
        run: php ./.github/workflows/build.php

And I was going to add mkdir("my dir") to the build.php but I think I’m missing the component that actually adds it to the release but not the repo

Actions don’t change your repo unless you explicitly tell them to, e.g. by making commits, so it’s perfectly safe to create whatever folders or files you need in your build. How to add those folders to the archive depends on how you create it. Also, git does not track empty folders as a matter of principle, so you couldn’t even add those to the repository if you wanted to. :wink:

After you have the archive you’ll need to add it to the release, but I’ll leave describing that to people who have experience with it.

Hi @moseleyi,

Git doesn’t track empty folder by default, have you pushed the code to github repo? Did you use .gitignore to create the folder which is simliar here?

‘branches’ only applied to event ‘push’ and ‘pull_request’, not for ‘release’, you can add job level if expression to check release branch instead.

if: github.event.release.target_commitish == 'master'  # check if the release branch is master

If you’d like to add to the release but not the repo, you need to zip the code and upload it as assets to the release(doc here):

POST https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets?name=foo.zip

image

Thanks

1 Like