GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Pushing to PR protected branch with token obtained from this action · actions/create-github-app-token · Discussion #75

Pushing to PR protected branch with token obtained from this action #75

Answered by gr2m
faileon asked this question in Q&A
Pushing to PR protected branch with token obtained from this action #75
@faileon faileon
Nov 3, 2023 · 1 comments · 2 replies
Answered by gr2m Return to top
Discussion options
  • Uh oh!

    There was an error while loading. Please reload this page.

  • Uh oh!

    There was an error while loading. Please reload this page.

faileon
Nov 3, 2023

Hello everyone,
I have created a custom GithubApp to which I gave permission to bypass branch protection rules (Allow specified actors to bypass required pull requests).

I have a workflow setup like this:

name: release

on: workflow_dispatch

jobs:
    release:
        runs-on: ubuntu-latest
        environment: production
        steps:
            - uses: actions/checkout@v3
              with:
                  fetch-depth: 0
                  ref: master
            - name: Use Node.js
              uses: actions/setup-node@v3
              with:
                  node-version: 18.10.0
            - name: Setup Git
              run: |
                  git config user.name "DWA Bot"
                  git config user.email "[email protected]"
            - name: DWA-bot auth
              id: dwa-bot
              uses: actions/create-github-app-token@v1
              with:
                  app-id: ${{ secrets.DWA_BOT_APP_ID }}
                  private-key: ${{ secrets.DWA_BOT_PRIVATE_KEY }}
            - name: Log in to Docker Hub
              uses: docker/login-action@v3
              with:
                  username: ${{ secrets.DOCKER_USERNAME }}
                  password: ${{ secrets.DOCKER_PASSWORD }}
            - run: npm ci
            - name: Version
              shell: bash
              run: npx nx affected --base=last-release --target=version --parallel=1
              env:
                  GITHUB_TOKEN: ${{ steps.dwa-bot.outputs.token }}
                  NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
                  PKG_GITHUB_TOKEN: ${{ secrets.PKG_GITHUB_TOKEN }}
            - name: Tag last-release
              shell: bash
              run: |
                  git tag -f last-release
            - name: Push changes
              uses: ad-m/github-push-action@master
              with:
                  github_token: ${{ steps.dwa-bot.outputs.token }}
                  branch: master
            - name: Push tags
              uses: ad-m/github-push-action@master
              with:
                  github_token: ${{ steps.dwa-bot.outputs.token }}
                  branch: master
                  force: true
                  tags: true

However the workflow still fails with the following erro:
remote: error: Changes must be made through a pull request.

Output from the create-github-app-token action seems to be OK:
owner and repositories not set, creating token for the current repository ("dwa")

Anyone could please shed some light on what I might be doing wrong?

Thank you.

You must be logged in to vote
All reactions
Answered by gr2m Nov 3, 2023

I don't think it's a problem with our action.

Can you please try to set persist-credentials: false for the checkout step?

            - uses: actions/checkout@v3
              with:
                  fetch-depth: 0
                  ref: master
                  persist-credentials: false
View full answer

Replies: 1 comment · 2 replies

Comment options
  • Uh oh!

    There was an error while loading. Please reload this page.

gr2m
Nov 3, 2023

I don't think it's a problem with our action.

Can you please try to set persist-credentials: false for the checkout step?

            - uses: actions/checkout@v3
              with:
                  fetch-depth: 0
                  ref: master
                  persist-credentials: false
You must be logged in to vote
All reactions
2 replies
@faileon
Comment options
  • Uh oh!

    There was an error while loading. Please reload this page.

faileon Nov 3, 2023
Author

Ah thank you so much, actions/checkout seems to indeed be the root cause of this issue.

After investigating further it seems that the checkout action persists the passed credentials by default and subsequent git commands will pick them up automatically... I did not expect that.

I believe your proposed solution works, I am also adding mine, which is to specify the token for the checkout action.

        steps:
            - name: DWA-bot auth
              id: dwa-bot
              uses: actions/create-github-app-token@v1
              with:
                  app-id: ${{ secrets.DWA_BOT_APP_ID }}
                  private-key: ${{ secrets.DWA_BOT_PRIVATE_KEY }}
            - uses: actions/checkout@v4
              with:
                  fetch-depth: 0
                  ref: master
                  token: ${{ steps.dwa-bot.outputs.token }}

This resolved the issue. Thanks again for the quick reply.

All reactions
  • 👍 2
@Dogacel
Comment options
  • Uh oh!

    There was an error while loading. Please reload this page.

Dogacel Oct 7, 2024

Thank you so much 🙇 I never realized checkout implicitly brought credentials.

All reactions
Answer selected by faileon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
3 participants
@faileon @gr2m @Dogacel
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.