英文:
How can I not gitignore in a Github Action?
问题
抱歉,标题中的措辞不太好。基本上,我有一个使用TypeScript(不是Node)的网站,我想通过Github Pages进行托管。我有一个tsconfig.json
文件,大致如下:
{
"compilerOptions": {
"rootDir": "./src",
"outDir": "./js"
},
"include": ["./src"]
}
我不想将编译后的代码放在主分支上,所以我的.gitignore
文件包含了以下内容:
js/
为了使我的项目在Github Pages上工作,我设置了action-build-typescript来将我的TypeScript编译到一个单独的分支上,这个分支将作为Github Pages的源代码。
on:
push:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout project
uses: actions/checkout@v3
- name: Build and push
uses: alexthemaster/action-build-typescript@master
with:
pushToBranch: true
branch: "gh-pages"
githubToken: ${{ secrets.GITHUB_TOKEN }}
这个方法很好用,但是js/
目录没有被创建。经过一番调查,发现当这个操作推送到gh-pages
分支时,.gitignore
仍然生效,因此我的JavaScript代码没有被提交。
有没有更好的方法可以解决这个问题?我应该将编译后的代码推送到main
分支吗?
英文:
Sorry for the poor wording in the title. Essentially, I have a website with Typescript (not Node) that I want to host via Github Pages. I have a tsconfig.json
that essentially looks like this:
{
"compilerOptions": {
"rootDir": "./src",
"outDir": "./js"
},
"include": ["./src"]
}
I don't want my compiled code on the main branch, so my gitignore contains
js/
In order to have my project work on Github Pages, I set up action-build-typescript to compile my Typescript onto a separate branch, which would be the source for Github pages.
on:
push:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout project
uses: actions/checkout@v3
- name: Build and push
uses: alexthemaster/action-build-typescript@master
with:
pushToBranch: true
branch: "gh-pages"
githubToken: ${{ secrets.GITHUB_TOKEN }}
This works great, however the js/
directory wasn't being created. Some digging revealed that when this action was pushing to the gh-pages
branch, the .gitignore
was still being applied, thus my Javascript wasn't being committed.
Is there a better way I can do this? Should I just push my compiled code to main
?
答案1
得分: 1
如果你在gh-pages
分支上添加一个提交,删除(或注释掉).gitignore
文件中的这一行,这些文件将会在该分支上的提交中被添加。
也许你需要先切换到gh-pages分支并从源分支合并,这样gh-pages分支上的.gitignore文件才会用于提交。
另一种方法是:
在构建和推送步骤之前,从.gitignore
文件中删除这一行。为了实现这一点,你可以在源分支中用一个准备好的.gitignore-pages
文件覆盖它。修改后的.gitignore文件将被提交到gh-pages
分支,但由于你可能永远不会将其合并回源分支,这不会有问题。
英文:
If you add a commit to the gh-pages
branch that removes (or comments out) this line in the .gitignore
file, the files will be added in commits on this branch.
Perhaps you have to checkout the gh-pages branch and merge from the source branch first, so that the .gitignore file from the gh-pages branch is used for the commit.
Alternative:
Remove the line from the .gitignore
file before the build and push step. To achieve this, you can just overwrite it with a prepared .gitignore-pages
file in your source branch. The changed .gitignore file will be committed to the gh-pages
branch, but since you probably will never merge ist back to your source branch, this will be no problem.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论