git-publish-subdir-action
git-publish-subdir-action copied to clipboard
Allow publishing contents of root directory via `ENV.FOLDER` variable
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 buildin./reactto generate./react/dist/... mkdir publicin the repo root, andmvall 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.
https://github.com/s0/git-publish-subdir-action/blob/43ac335eeb72a66d16e1834228a5178453478de7/action/src/index.ts#L407
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 });
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
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 }}