将网站部署到github上

    科技2026-08-19  12

    将网站部署到github上

    Recently I start a new project called DevData Tools what is an online tool that provides a set of tools useful for specific necessities, the core of the project was a tool with utilities to easily create use cases description and test cases description and export to PDF as table format, the tool is useful to who not deal easily with Word files and tables in there, but this is subject enough to write another article…

    最近,我启动了一个名为DevData Tools的新项目,这是一个在线工具,提供了一系列可满足特定需求的工具,该项目的核心是带有实用工具的工具,可以轻松创建用例描述和测试用例描述,并以PDF格式导出为PDF。表格格式,该工具对于不轻松处理其中的Word文件和表格的人很有用,但这足以编写另一篇文章……

    In this context I was deploying the front-end application to Firebase hosting and the back-end application to the Heroku, with the front-end was easily configured with file .yml for the workflow of github action, the Firebase Action made all the proccess of deploy, being necessary only the token, that I stored in a secret of the Github Repo.

    在这种情况下,我正在将前端应用程序部署到Firebase托管,而将后端应用程序部署到Heroku,其中前端使用文件.yml轻松配置为github操作的工作流,而Firebase Action则完成了所有流程部署,仅是令牌,我存储在Github Repo的秘密中。

    name: Firebase CI - CD on: push: branches: [ master ] jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@master - uses: actions/setup-node@master with: node-version: 12 - run: npm install --global yarn - run: yarn install - run: CI=false yarn build - uses: w9jds/firebase-action@master with: args: deploy --only hosting env: FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}

    Until now all was fine, but the point is when I went deploy the back-end application that’s I write in Golang, all the setup and file was fine, the problem was in my devdatatools-firebase-adminsdk.json file that I added they on my .gitignore file in the root of the repo when I uploading to the Github, but this was intentional.

    到目前为止,一切都还不错,但是关键是当我部署用Golang编写的后端应用程序时,所有设置和文件都还不错,问题出在我添加了它们devdatatools-firebase-adminsdk.json文件中当我上传到Github时,在.gitignore根目录的.gitignore文件中,但这是故意的。

    Ignoring my devdatatools-firebase-adminsdk.json 忽略我的devdatatools-firebase-adminsdk.json

    This file have to be ignored, why have some private keys about admin sdk of Firebase, so when I deployed locally all was fine, because was there, but in CI the heroku action was getting the HEAD of the branch, in this case master and deploying to heroku without this file. The point is that I had to create this file in runtime of workflow to deploy to Heroku. In this point my .yml file of workflow it was like this:

    这个文件必须被忽略,为什么要有一些有关Firebase的admin sdk的私钥,所以当我在本地部署时一切都很好,因为在那里,但是在CI中,heroku动作是获取分支的HEAD ,在这种情况下是master和在没有此文件的情况下部署到heroku。 关键是我必须在工作流的运行时中创建此文件才能部署到Heroku。 在这一点上,我的工作流程.yml文件是这样的:

    on: push: branches: [ master ] jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@master - uses: actions/setup-go@v1 with: go-version: '1.14.6' - run: cd src && go mod vendor # Necessity to create the json file here... and commit this to the HEAD (master) - uses: akhileshns/heroku-deploy@v3.4.6 with: heroku_api_key: ${{ secrets.HEROKU_API_KEY }} heroku_app_name: "dev-data-tools-api-golang" heroku_email: "jose.daniell@outlook.com" appdir: "src"

    All the actions in the Github Marketplace didn’t handle my need very well, the one that came closest was create-env-json but I needed to create the .json file in a subfolder src and also with a more dynamic way, like pass all the json in a secret of the repo or in a string of the action attribute.

    Github Marketplace中的所有动作都不能很好地满足我的需求,最接近的动作是create-env-json但是我需要在子文件夹src创建.json文件,并且还需要采用更动态的方式,例如pass所有的json都在存储库的秘密中或在action属性的字符串中。

    So I started to search how actions works, and I discovered that I could use my Javascript Knowledge to write a action using Node Environment, the first reading was about the core dependencie, what have the core functionality to get deal when you are running your action.

    因此,我开始搜索动作的工作原理,发现可以使用Java知识通过Node Environment编写动作,第一读是关于核心依赖性,在执行动作时有哪些核心功能需要处理。

    Creating a simple npm project with git init and adding as dependency, all the environment to execute the writing of the .json file was in my hands. There were many tests to understand how env variables of an action was receiveid, the docs of github help me a lot:

    使用git init创建一个简单的npm项目并将其添加为依赖项,所有执行.json文件编写的环境都在我手中。 有很多测试可以了解动作的env变量是如何被接收的,github的文档对我有很大帮助:

    You can view the code of action on this repository:

    您可以在此存储库上查看操作代码:

    The deploy of an action is very easy, when you respect all the requirements of action.yml file describing the action and the index.js file with the funcionality declared as entry point in the package.json file, only remains to create a new release, on the Github Repository.

    当您尊重描述该动作的action.yml文件和index.js文件的所有要求,并且在action.yml声明了package.json文件的入口点时,该动作的部署就非常容易,仅需创建一个新版本即可,位于Github存储库中。

    And now if you need to create a json file in runtime of your workflow, you can easily add this action on your .yml file of workflow.

    现在,如果您需要在工作流的运行时创建一个json文件,则可以轻松地将此操作添加到工作流的.yml文件中。

    In the final my workflow file was using my recently published action to work properly:

    最后,我的工作流程文件正在使用我最近发布的操作来正常工作:

    name: Heroku CI - CD on: push: branches: [ master ] jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@master - uses: actions/setup-go@v1 with: go-version: '1.14.6' - run: cd src && go mod vendor - name: create-json id: create-json uses: jsdaniell/create-json@1.1.2 with: name: "devdatatools-firebase-adminsdk.json" json: ${{ secrets.CREDENTIALS_JSON }} dir: "src/" - run: git config --global user.email "jose.daniell@outlook.com" && git config --global user.name "jsdaniell" && git add . && git add --force src/devdatatools-firebase-adminsdk.json && git status && git commit -a -m "Deploy Heroku Commit" - uses: akhileshns/heroku-deploy@v3.4.6 with: heroku_api_key: ${{ secrets.HEROKU_API_KEY }} heroku_app_name: "dev-data-tools-api-golang" heroku_email: "jose.daniell@outlook.com" appdir: "src"

    All the tests of both action and my deploy on Heroku, takes two days of my weekend, but worth it a lot!

    我在Heroku上进行动作和部署的所有测试都花费了我周末的两天时间,但是非常值得!

    翻译自: https://medium.com/swlh/how-i-create-my-first-action-and-deployed-to-github-actions-marketplace-8ca519be1ef7

    将网站部署到github上

    Processed: 0.014, SQL: 9