我正在尝试编写一个 GitHub 操作,将我的存储库中的文件副本复制到存储库中的不同子目录中。这是我的目录结构(复制文件之前)
my_project
|_ .github
| |_ workflows
| |_ run_tests.yml
| |_ copy_file.yml
|_ tests
| |_ testthat
| |_ test1.R
| |_ test2.R
|_ my_file.json
|_ copyfile.sh
这就是我希望复制文件后的文件结构
my_project
|_ .github
| |_ workflows
| |_ run_tests.yml
| |_ copy_file.yml
|_ tests
| |_ testthat
| | |_ test1.R
| | |_ test2.R
| |_ copy_of_my_file.json
|_ my_file.json
|_ copyfile.sh
所以基本上,我的 GitHub 操作应该制作
my_file.json
的副本,命名为 copy_of_my_file.json
并将其放置在 tests
子目录中。我用以下内容构建了一个 bash
脚本
#!/bin/bash
cp my_file.json tests/copy_of_my_file.json
在本地,我运行
chmod u+x copyfile.sh
,然后运行 bash copyfile.sh
,文件确实被复制了。我的copy_file.yml
工作流程如下:
name: Copy my_file.json to tests subdirectory
on: [push, pull_request, workflow_dispatch]
jobs:
run:
runs-on: [ubuntu-latest]
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2
- name: Make copy of my_file.json 📚
run: |
chmod u+x "${GITHUB_WORKSPACE}/copyfile.sh"
bash "${GITHUB_WORKSPACE}/copyfile.sh"
该操作运行时没有错误,但文件未被复制。我尝试了 GitHub Marketplace 中的其他操作,但没有成功。我还尝试将操作的
run
更改为简单的 cp my_file.json tests/copy_of_my_file.json
但它也不起作用。
问题是文件需要提交到存储库。人们可以编写自己的提交操作或从GitHub Actions Marketplace中选择。
在后台,操作在 GitHub 服务器上运行。签出操作从存储库中获取文件。之后所做的任何事情都发生在该服务器中。因此,任何需要“保存”的内容都必须推送到存储库或生成操作工件。