Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for publish_branch that is the same as the triggering branch? #358

Closed
trangdata opened this issue Jun 21, 2020 · 12 comments
Closed
Assignees
Labels

Comments

@trangdata
Copy link

Currently, we're getting the following error for this CI config:

Setup auth token
  [INFO] setup GITHUB_TOKEN
  ##[error]Action failed with "You deploy from PMLB2.0 to PMLB2.0"

From #245, it sounds like this is the intended behavior to:

When users set a publish_branch that is the same as a branch triggered by the workflow, this action stops the deployment to protect the branch.

In our case, we use CI to regenerate some files. The use case is similar to linting. Imagine CI is used to lint files that should be committed back to the same branch.

What are the reasons that publishing to the triggering branch is forbidden? Is there a workaround?

@peaceiris
Copy link
Owner

When you set a branch name as the same as the triggering branch, it will overwrite all files with the files under the publish_dir. We cannot run the next CI on the branch.

I read your YAML but I do not understand what you want to do. Do you know the GitHub Pages spec and basic usage? Could you tell me what is your deployment assets?

@peaceiris
Copy link
Owner

What are the reasons that publishing to the triggering branch is forbidden?

Let's imagine a project powered by Static Site Generators. We are managing source files (Markdown and template files) and generating output files like HTML, CSS, and JavaScript files. In this case, when we set a branch name as the same as the triggering branch, it will overwrite all Markdown files with the HTML files under the publish_dir. We cannot run the next CI on the branch.

@trangdata
Copy link
Author

Prior to deployment, CI rebuilds READMEs that change when data ends up changing. We want the READMEs on a branch to automatically update when the data on that branch change.

Copying the relevant section of our workflow:

    - name: Deploy
      uses: peaceiris/actions-gh-pages@v3
      with:
        # external_repository: ${{ github.repository }}
        github_token: ${{ secrets.GITHUB_TOKEN }}
        publish_dir: .
        publish_branch: ${{ env.BRANCH }}
        # without keep_files, .github/workflows/pythonapp.yml was removed
        keep_files: true

it will overwrite all files with the files under the publish_dir

That is the goal. When CI changes a file, we want that change to be pushed back to the triggering branch.

We cannot run the next CI on the branch.

We don't want CI to run on the CI-generated commit, although it's not terrible if it does, since there shouldn't be any new changes and deployment would therefore be skipped. Setting keep_files: true ensures the .github directory is not removed.

it will overwrite all Markdown files with the HTML files under the publish_dir. We cannot run the next CI on the branch.

In our case, we set publish_dir: .. I don't think deployment to triggering branches makes sense unless publish_dir is the repository root.

@peaceiris
Copy link
Owner

That is the goal. When CI changes a file, we want that change to be pushed back to the triggering branch.

This action does not support this use case.

I just recommend you to use git commands.

- name: update
  run: |
    git add .
    git commit -m "update"
    git push origin YOUR_BRANCH

@trangdata
Copy link
Author

This action does not support this use case. I just recommend you to use git commands.

Okay good to know. I imagine we'd also have to configure git to use secrets.GITHUB_TOKEN?

Regarding the initial error message of You deploy from PMLB2.0 to PMLB2.0. The message doesn't imply that this is forbidden. Possibly it would be more clear to output something like:

Stopping deployment from PMLB2.0 to PMLB2.0. Deploying to the triggering branch is not allowed.

Thanks for the quick responses!

@peaceiris
Copy link
Owner

The actions/checkout already manages it. We can just run as follows.

      - name: update
        run: |
          git config --local user.name 'github-actions[bot]'
          git config --local user.email 'github-actions[bot]@users.noreply.github.com'
          echo "hoge" >> README.md
          git commit -am "add hoge"
          git push origin master

@peaceiris
Copy link
Owner

Stopping deployment from PMLB2.0 to PMLB2.0. Deploying to the triggering branch is not allowed.

Thank you for the feedback! I will work on it at #359

@fabiendem
Copy link

Hey @peaceiris, any chance you could make this constraint (no same branch deploy) non-blocking when the deploy is for an external repository?
https://github.com/peaceiris/actions-gh-pages#%EF%B8%8F-deploy-to-external-repository

This is a case where a same branch deploy would make sense.

I can open a new issue if you wish so.

Thanks!

@peaceiris
Copy link
Owner

peaceiris commented Jun 27, 2020

@fabiendem
This safety behavior is only for deploying to a branch on the same repository. I think you are using the wrong auth method.

README.md

You can use deploy_key or personal_token. When you use deploy_key, set your private key to the repository which includes this action and set your public key to your external repository.

OR

Note that GITHUB_TOKEN has no permission to access to external repositories. Please create a personal access token and set it to personal_token like personal_token: ${{ secrets.PERSONAL_TOKEN }}.

@peaceiris
Copy link
Owner

If you have another question, ask here or open another issue.

@fabiendem
Copy link

Hey thank you,
I think I was trying to use ${{ secrets.PERSONAL_TOKEN }} on a github_token, but the error message was a bit misleading.
Anyway, all good now

peaceiris pushed a commit that referenced this issue Jul 8, 2020
peaceiris pushed a commit that referenced this issue Jul 8, 2020
@github-actions
Copy link
Contributor

This issue has been LOCKED because of it being resolved!

The issue has been fixed and is therefore considered resolved.
If you still encounter this or it has changed, open a new issue instead of responding to solved ones.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants