Answer a question

So I deploy my site using composer. Composer pulls down an entire repo by branch name. I want to develop using a main branch with a .gitignore that ignores the build folder of a React app. When Composer deploys I use a different branch one that has the .gitignore allowing the build folder. When I push to the main branch I would like to merge main into compiled-main checkout compiled-main delete the .gitignore and run yarn install yarn build

  • git checkout master
  • merge master -> compiled-master
  • git checkout compiled-master
  • rm .gitignore
  • mv compiled-gitignore .gitignore
  • yarn install
  • yarn build
  • git add .
  • git commit -m 'message'
  • git push

Here are my actions:

build:
name: Build
runs-on: ubuntu-latest

steps:
  - name: checkout master branch
    uses: actions/checkout@master
  - name: Merge master -> compiled-master
    uses: devmasx/merge-branch@v1.3.1
    with:
      type: now
      from_branch: master
      target_branch: compiled-master
      github_token: ${{ github.token }}
  - name: checkout compiled-master branch
    uses: actions/checkout@v2
    with:
      ref: compiled-master
      persist-credentials: false
  - run: |
      rm .gitignore 
      mv compiled-gitignore .gitignore
      yarn install
      yarn build
      git config --local user.email 'xxx@xxx.edu'
      git config --local user.name 'xxx'
      git add .
      git commit -m "Add new gitignore & build"
  - name: Push changes
    uses: ad-m/github-push-action@master
    with:
      github_token: ${{ secrets.Secret_Bot_token }}
      branch: 'compiled-master'

Unfortunately everything works until I try to push the build files and the new .gitignore up to the compiled-master branch. I am getting a message that the url for the repo is not accessible. However if I click the link directly from the error the repo url resolves???

Error: fatal: unable to access 'https://github.com/nxxx/xxx-react-app/': URL using bad/illegal format or missing URL

So at first I got the error above. So I edited my secret to be very simple so I knew it would not send any character that might bust the encoding. So it seems I no longer get the invalid url message now I get the error: "remote: Invalid username or password. fatal: Authentication failed for 'https://github.com/xxx/xxx-react-app.git/' Error: Process completed with exit code 128." But I have checked the username and it is correct. Maybe after changing the secret it takes time to work?

Also tried this:

build:
name: Build
runs-on: ubuntu-latest

steps:
  - name: checkout master branch
    uses: actions/checkout@master
  - name: Merge master -> compiled-master
    uses: devmasx/merge-branch@v1.3.1
    with:
      type: now
      from_branch: master
      target_branch: compiled-master
      github_token: ${{ github.token }}
  - name: checkout compiled-master branch
    uses: actions/checkout@v2
    with:
      ref: compiled-master
      persist-credentials: false
      fetch-depth: 0
  - run: |
      rm .gitignore 
      mv compiled-gitignore .gitignore
      yarn install
      yarn build
      git config --local user.email 'xxx.edu'
      git config --local user.name 'xxx'
      git remote set-url origin https://x-access-token:${{ secrets.Secret_Bot_token }}@github.com/${{ github.repository }}.git
      git add .
      git commit -m "Add new gitignore & build"
      git push

The repo I am trying to run these commands in and push to is a private repo. But I thought that is what the secret code is for. everything is running in the same repo.

Answers

Under the devmasx/merge-branch@v1.3.1 action, you need to replace

the line github_token: ${{ github.token }}

with github_token: ${{ secrets.GITHUB_TOKEN }}

Next, since you are getting error in commiting files I would recommend you to use

- uses: stefanzweifel/git-auto-commit-action@v4
  with:
    commit_message: Add new gitignore & build
    branch: compiled-master

So finally your new code should be:

build:
name: Build
runs-on: ubuntu-latest

steps:
  - name: checkout master branch
    uses: actions/checkout@master
  - name: Merge master -> compiled-master
    uses: devmasx/merge-branch@v1.3.1
    with:
      type: now
      from_branch: master
      target_branch: compiled-master
      github_token: ${{ secrets.GITHUB_TOKEN }}
  - name: checkout compiled-master branch
    uses: actions/checkout@v2
    with:
      ref: compiled-master
  - run: |
      rm .gitignore 
      mv compiled-gitignore .gitignore
      yarn install
      yarn build
  - uses: stefanzweifel/git-auto-commit-action@v4
    with:
      commit_message: Add new gitignore & build
      branch: compiled-master

You can read more about secrets here.

Logo

ModelScope旨在打造下一代开源的模型即服务共享平台,为泛AI开发者提供灵活、易用、低成本的一站式模型服务产品,让模型应用更简单!

更多推荐