varunsridharan / action-github-workflow-sync

Github Action To Sync Github Action's Workflow Files Across Repositories
https://github.com/marketplace/actions/github-workflow-sync
MIT License
60 stars 16 forks source link

Ability to copy everything from a source folder to destination path/folder #2

Closed sunn-e closed 2 years ago

sunn-e commented 4 years ago

I tried passing the path as traditional "path/to/folder/*" to get every file in a folder but it does not work. This feature can come handy when you have many files in source folder.

varunsridharan commented 4 years ago

This feature Added in 2.0

wagnst commented 3 years ago

hi @varunsridharan did you test this feature? Actually for me it does not work, when copying a folder. It always says:

  terraform=.github/workflows
    ✔  xxx/workflows/terraform => .github/workflows
  Error:    🛑️  Unable To Copy File.
  Error: no such file or directory: /home/runner/work/yyy/yyy/xxx/workflows/terraform/\.

I have a folder with subfolder structure and files that shall be copied by this inside the workflows folder (I do use composite feature of actions inside here)

varunsridharan commented 3 years ago

@wagnst can you please provide your workflow yaml file ?? Just the workflow copy action's yml will do

wagnst commented 3 years ago

@varunsridharan sure, please see here:

where terraform is a folder inside the <ORG name>/workflows folder (which is in the ROOT of the repo). It shall go into .github/workflows. I see in the message its detected correctly, but it seems the cp command actually gives the error output.

terraform folder has 4 subfolders, where in each subfolder there is one file each called action.yml. Its an implementation using the new actions composite feature that i would like to sync as well. For composite check here: https://docs.github.com/en/actions/creating-actions/creating-a-composite-run-steps-action

name: Workflow Sync for landingzone git repositories

on:
  push:
    branches:
      - master
    paths:
      - '.github/workflows/**'
      - '<ORG name>/**'
  schedule:
    - cron: "0 0 * * *" # Run at the end of every day
  workflow_dispatch:

env:
  DRY_RUN: false
  TF_WORKSPACE_REPOSITORIES: |
    <ORG name>/base-landingzone
  TF_WORKSPACE_WORKFLOW_FILES: |
    tf-workspace-master.yml
    tf-workspace-pr.yml
    tf-workspace-editorconfig=.editorconfig
    tf-workspace-gitignore=.gitignore
    tf-workspace-CODEOWNERS=.github/CODEOWNERS
    pull_request_template.md=.github/pull_request_template.md
    dependabot.yml=.github/dependabot.yml
    terraform=.github/workflows
jobs:
  github-repo-sync-tf-workspaces:
    name: "File sync for tf workspace repositories"
    runs-on: ubuntu-latest
    steps:
      - name: Fetching Local Repository
        uses: actions/checkout@master
      - name: Running Workflow Sync
        uses: varunsridharan/action-github-workflow-sync@main
        with:
          DRY_RUN: ${{ env.DRY_RUN }}
          REPOSITORIES: ${{ env.TF_WORKSPACE_REPOSITORIES }}
          WORKFLOW_FILES: ${{ env.TF_WORKSPACE_WORKFLOW_FILES }}
          GITHUB_TOKEN: ${{ secrets.SYNC_TOKEN }}
          PULL_REQUEST: true
          COMMIT_MESSAGE: "Sync of files from <ORG name>/base-landingzone"
varunsridharan commented 3 years ago

@wagnst i am confused seeing your config. can you please tell me exactly where terraform folder is located ?

wagnst commented 3 years ago

hey @varunsridharan, thanks!

<repo root>
- /<github org name>
  - /workflows
    - /terraform
      - /subfolder1
        - action.yml 
      - /subfolder2
        - action.yml  

And terraform folder (with subfolders, etc.) it sould be copied to another repo into: .github/workflows Does this help?

varunsridharan commented 3 years ago

@wagnst thanks

the path should be like this ./<github org name>/workflows/terraform

env:
  DRY_RUN: false
  TF_WORKSPACE_REPOSITORIES: |
    <ORG name>/base-landingzone
  TF_WORKSPACE_WORKFLOW_FILES: |
    tf-workspace-master.yml
    tf-workspace-pr.yml
    tf-workspace-editorconfig=.editorconfig
    tf-workspace-gitignore=.gitignore
    tf-workspace-CODEOWNERS=.github/CODEOWNERS
    pull_request_template.md=.github/pull_request_template.md
    dependabot.yml=.github/dependabot.yml
-    terraform=.github/workflows
+   ./<github org name>/workflows/terraform=.github/workflows
wagnst commented 3 years ago

@varunsridharan i also tried that. Also now again, it does not work:

  ./<github org name>/workflows/terraform=.github/workflows
    ✔  <github org name>/workflows/terraform => .github/workflows
  Error:    🛑️  Unable To Copy File.
  Error: no such file or directory: /home/runner/work/<dest repo>/<dest repo>/<github org name>/workflows/terraform/\.

Config for that run is:

  TF_WORKSPACE_WORKFLOW_FILES: |
    ./<github org name>/workflows/terraform=.github/workflows
varunsridharan commented 3 years ago

@wagnst sorry about that. I will try to replicate the same in my test env and update you on this. in the mean time if you could share the repo and the full action log i might guess what exactly happening .

wagnst commented 3 years ago

@varunsridharan thanks! What exactly else do you require? Other output relevant for that I cannot find in the logs. Unfortunately i cannot share the repo with you in full as it contains private information. But let me know what exactly I can test to help figure out / debug the issue! I think you can also easily reproduce it

afirth commented 3 years ago

Same issue. I suspect the problem is at path/\. which seems to be coming from https://github.com/varunsridharan/actions-js-toolkit/blob/main/src/path/index.js#L24 -- my guess is that the extra \ is breaking for actions/io, even though it works fine for cp. PR incoming, which makes it work but throws an error without the trailing /, at least on source. It works with or without though

Tree

$ tree
.
├── github-actions
│   └── k8s
│       ├── kustomize-lint.yaml
│       └── skaffold-deploy.yaml
└── README.md

Sample (working, no slash):

  # github-actions/k8s/=.github/workflows/ # << this works without errors
  Error: 🛑️  Unable To Find Source File !

  github-actions/k8s=.github/workflows # << this throws an error with the incoming PR, but still works
    ✔  github-actions/k8s => .github/workflows
  ✔  [file-sync-6-master-1622566039 59d9344] 💬 - Files Synced | Runner ID : 6 | ⚡ Triggered By FATMAP/github-file-sync
   2 files changed, 135 insertions(+)
   create mode 100644 .github/workflows/k8s/kustomize-lint.yaml
   create mode 100644 .github/workflows/k8s/skaffold-deploy.yaml

Broken

  github-actions/k8s=.github/workflows
    ✔  github-actions/k8s => .github/workflows
  Error:    🛑️  Unable To Copy File.
  Error: no such file or directory: /home/runner/work/github-file-sync/github-file-sync/github-actions/k8s/\. # << perhaps the extra \?
    No changes detected
GitHub
varunsridharan/actions-js-toolkit
Predefined Functions For Github Actions NodeJS. Contribute to varunsridharan/actions-js-toolkit development by creating an account on GitHub.