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

Why need to login in CI? #739

Closed
matteodisabatino opened this issue Feb 14, 2021 · 6 comments
Closed

Why need to login in CI? #739

matteodisabatino opened this issue Feb 14, 2021 · 6 comments

Comments

@matteodisabatino
Copy link

matteodisabatino commented Feb 14, 2021

Hi,
I made a module in which I use release-it (via Github Actions) to create release and tag but not for publish to npm. Here the code:

name: CI

on:
  push:
    branches: [master]

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Use Node.js 14
        uses: actions/setup-node@v1
        with:
          node-version: "14"
      - name: git config
        run: |
          git config user.email "matteo.di.sabatino.1989@gmail.com"
          git config user.name "Matteo Di Sabatino"
      - run: npm i
      - run: npm test
      - run: npm run release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

## Other jobs down there

The job work fine but I cannot understand why I need to run "git config" if there is an access token. Note that "secrets.GITHUB_TOKEN" is a special access token, generated by CI directly, that owns all permission in the repo; if I use an access token of mine (that I called "secrets.AT") there is no change: I always have to make "git config".

I would like to know if this is normal or if I'm missing something. And if this is the correct behaviour, I would like to know if there is a clean way that let me avoid specify my personal information (although they are public).

Thanks in advance.

@webpro
Copy link
Collaborator

webpro commented Feb 15, 2021

This information is needed to assign the git commit to a user. If it's not configured by the CI environment, or if the CI git user is not the user you want to assign to this release commit, you would need to change it. You could also do something like this (not sure about the exact variable names):

git config --global user.name "${CI_USERNAME}"
git config --global user.email "${CI_EMAIL}"

The above is only relevant to the Git repository (commit/tag/push). On the other hand, the GITHUB_TOKEN is indeed enough for the GitHub Release, which is done using the GitHub API.

@matteodisabatino
Copy link
Author

Thank you very much 😀. Later i check which variables are available in github actions.

@matteodisabatino
Copy link
Author

It seems that in Github actions the best practice is use this:

git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"

I'll try and I'll let you know 😉

@webpro
Copy link
Collaborator

webpro commented Feb 17, 2021

Thanks @matteodisabatino, please let me know so we can update the docs.

@matteodisabatino
Copy link
Author

matteodisabatino commented Feb 17, 2021

@webpro I confirm that with the above settings the CI works (CI settings, the release). Notice that I haven't used the option "--global".

Notice also that this a test repo has been created for this purpose only. I'll delete it very soon, probably at the end of the day.

@webpro webpro closed this as completed in 45a149b Feb 22, 2021
@morpheus65535
Copy link

New syntax seems to be ${{github.actor}}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants