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

Allow publishing contents of root directory via ENV.FOLDER variable #31

Open
scottalguire opened this issue Nov 12, 2020 · 3 comments
Open
Labels

Comments

@scottalguire
Copy link

The FOLDER environment variable allows defining a subdirectory whose contents are copied into the destination BRANCH, however it does not support copying the entire repo contents into the destination, ie:

env:
  REPO: self
  BRANCH: production
  FOLDER: ./
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

In fairness, this may be out of scope for this action given that it is called "git-publish-subdir-action" but I found it to be relevant in publishing a wordpress plugin where I need to run webpack in one of the subdirectories and I wanted to keep the generated files out of the main branch, but I also need files in the repo root to be part of the release.

The current workaround is to either fork and update github-publish-subdir-action, or to create a preceeding job that:

  • Runs npm run build in ./react to generate ./react/dist/...
  • mkdir public in the repo root, and mv all the files and directories in / into it

This allows setting FOLDER to "public" in order to copy the repo root contents into the destination branch.

await exec(`cp -rT ${folder}/ ./`, { env, cwd: REPO_TEMP });

For consideration

Use rsync to copy the folder contents of the source repo to the destination branch root, but exclude the .git folder in case FOLDER is set to ./

- await exec(`cp -rT ${folder}/ ./`, { env, cwd: REPO_TEMP }); 
+ await exec(`rsync -avz ${folder}/ ./ --exclude=".git"`, { env, cwd: REPO_TEMP }); 
@Jaid
Copy link

Jaid commented Jun 10, 2021

I was also in need for a feature like this, because Cloudflare Pages needs to receive updates from a non-master branch that must have the same folder structure as the master branch's content.

This is my workaround:

name: Publish to Pages
on:
  push:
    tags: ["v[0-9]+.[0-9]+.[0-9]+"]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: actions/checkout
        uses: actions/[email protected]
      - name: Copy content to subdirectory # https://github.com/s0/git-publish-subdir-action/issues/31
        run: mkdir /tmp/pages && cp --recursive . /tmp/pages && mv /tmp/pages ./pages
      - name: Deploy
        uses: s0/[email protected]
        env:
          REPO: self
          BRANCH: pages
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          FOLDER: pages

@scottalguire
Copy link
Author

I was also in need for a feature like this, because Cloudflare Pages needs to receive updates from a non-master branch that must have the same folder structure as the master branch's content.

This is my workaround:

name: Publish to Pages
on:
  push:
    tags: ["v[0-9]+.[0-9]+.[0-9]+"]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: actions/checkout
        uses: actions/[email protected]
      - name: Copy content to subdirectory # https://github.com/s0/git-publish-subdir-action/issues/31
        run: mkdir /tmp/pages && cp --recursive . /tmp/pages && mv /tmp/pages ./pages
      - name: Deploy
        uses: s0/[email protected]
        env:
          REPO: self
          BRANCH: pages
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          FOLDER: pages

Nice 👍 I ended up using a similar workaround, except with rsync:

...
      - name: Install dependencies
        working-directory: ./react
        run: npm install

      - name: Build app
        working-directory: ./react
        run: npm run build
          
      - name: Move generated files into ./public
        working-directory: ./
        run: rsync -avz ./* ./public/ --exclude=node_modules --exclude=.gitignore
      
      - name: List files
        working-directory: ./
        run: pwd && ls -lha
        
      - name: Push git subdirectory as branch
        uses: s0/[email protected]
        env:
          REPO: self
          BRANCH: production
          FOLDER: public
          SQUASH_HISTORY: false
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

@s0 s0 added feature request good first issue Good for newcomers labels Feb 8, 2022
@Dmytro-K
Copy link

Workaround with rsync works. But I also need to update submodule commit on build branch. Is it possible somehow?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants