coverallsapp / github-action

Coveralls Github Action
https://coveralls.io
MIT License
468 stars 75 forks source link

Documentation Request- Add GitHub Secrets Exmaple #53

Open ericdmoore opened 4 years ago

ericdmoore commented 4 years ago

I found the JS/TS documentation a bit confusing as how to integrate the GithubActions/ CI. I really struggled on how to inject the secret: COVERALLS_REPO_TOKEN

I could not get the coveralls github action to work... not sure if that was my laziness in not wanting to read more on the Github Actions or if there is bug...

I eventually ended up usiung Github Secrets and the solution involves less magic (AKA GitHub Action Magic)

NPM Config Example

package.json full reference is below

{ 
  "scripts":{
     "test": "nyc ts-node test/index.test.ts",
     "reportCov": "nyc report --reporter=text-lcov | coveralls",
}

GitHub Action File Exmaple

nodejs.yml full reference is below

name: Build & Tests
on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]
jobs:

  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [10.x, 12.x, 14.x]
    steps:
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - name: CheckOut Latest
      uses: actions/checkout@v2
    - run: npm ci
    - run: npm run lint
    - run: npm run build --if-present

  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [10.x, 12.x, 14.x]
    steps:
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - name: CheckOut Latest
      uses: actions/checkout@v2
    - run: npm ci
    - name: Run Tests + Report Coverage
      env: 
        COVERALLS_SERVICE_NAME: 'GitHub CI'
        COVERALLS_GIT_BRANCH: master
        COVERALLS_REPO_TOKEN : ${{ secrets.COVERALLS_REPO_TOKEN }}
        NODE_COVERALLS_DEBUG: 0 # or 1 for verbsoe
      run: |
        npm run test && 
        npm run reportCov

Notice

All I needed to know when getting started with GitHub Actions was this line in the nodejs.yml COVERALLS_REPO_TOKEN : ${{ secrets.COVERALLS_REPO_TOKEN }}

...Just thought I would drop this in your issues so that any future person searching through here might be able to scratch their own itch on how to integrate their npm run scripts and GitHub Actions/ CI

Anyway nice product and keep up the great work. I am new user, and enjoying it so far.

Referenced Files

For the files in the wild, the two full blown config files are:

ericdmoore commented 4 years ago

I'd love to hear your perspective on this implementation - perhaps there are features I am leaving on the table from your GitHub Action

Swarag-N commented 4 years ago

🙏🙏🙏 Thank you, for posting this. This is the easiest way, i can think of for setting up a workflow (with REPO-TOKEN). After struggling with all different kinds of errors, i came across this issue.

Since Github actions are new, There are very few (nothing for my setup) blogs and videos for setting up this. It would be helpful for other peeps if you write a blog about this setup. So, it would be accessible to an easier rate.

ericdmoore commented 4 years ago

Hey @Swarag-N thanks for the good vibes. I think I might write this up after all... I was hoping that there would have been more back and forth from the coveralls folks. But this is really one of my first real-suggestion-issue to an open source product, albeit still documentation oriented.

Perhaps I had overly optimistic expectations on response times.

juanvillegas commented 3 years ago

Although this works, the setup doesn't even use the github-action that this repo is for. What you have done is an integration between coveralls-node and Github Actions. When you use the action provided in this repository, the github token is used to find the corresponding repository in Coveralls, and thus the repository token is not needed. Or at least that's my understanding.

But I will agree with you that a lot of work is needed in the documentation of this product, specially given that it has a paid version.