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

Allow to work on pull_request and master branch #3

Closed
adriaandotcom opened this issue Jan 16, 2020 · 4 comments
Closed

Allow to work on pull_request and master branch #3

adriaandotcom opened this issue Jan 16, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@adriaandotcom
Copy link

Not sure if this is possible, but it would be nice to have only one step instead of these two:

- name: Prettier Action on PR
  if: github.event_name == 'pull_request'
  uses: creyD/prettier_action@v1.0
  with:
    prettier_options: "--write {**/*,*}.{js,html,json,md,yml,css,scss}"
    branch: ${{ github.head_ref }}
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Prettier Action on master
  if: github.event_name == 'push' && github.ref == 'refs/heads/master'
  uses: creyD/prettier_action@v1.0
  with:
    prettier_options: "--write {**/*,*}.{js,html,json,md,yml,css,scss}"
    branch: master
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Somehow it would be nice to not have to specify a branch. That is automatically would know if it's a PR or if it's just a push. If it's not available in your app than we could do something like this:

- name: Prettier Action
  uses: creyD/prettier_action@v1.0
  with:
    prettier_options: "--write {**/*,*}.{js,html,json,md,yml,css,scss}"
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    event_name: ${{ github.event_name }}
    ref: ${{ github.ref }}
@adriaandotcom adriaandotcom added the enhancement New feature or request label Jan 16, 2020
@creyD
Copy link
Owner

creyD commented Jan 16, 2020

This isn't really possible because -as for the GITHUB_TOKEN-, my repository and therefore the Action can't access the issuing (your) repository. Even if you provide the event name, my action doesn't know where to push to. If you just only want to merge to the origin branch, then this should do the job -the on parameter is documented here:

on: [push, pull_request]
- name: Prettier Action on master
  if: github.event_name == 'push' && github.ref == 'refs/heads/master'
  uses: creyD/prettier_action@v1.0
  with:
    prettier_options: "--write {**/*,*}.{js,html,json,md,yml,css,scss}"
    branch: ${{ github.ref }}
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

The branch SHOULD be filled with master automatically if it's the on push event.

@adriaandotcom
Copy link
Author

adriaandotcom commented Jan 16, 2020

I'm already using the on parameter like this:

on:
  pull_request:
    types: [opened, synchronize]
  push:
    branches:
      - master

Which works great.

I think I'm not clear on what I would love to have. I would love that the GitHub Action would work without specifying the branch. Or where it would work for both a PR and for a normal push.

Maybe this works?

on:
  pull_request:
    types: [opened, synchronize]
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [12.x]

    steps:
      - name: Prettier Action on master
        uses: creyD/prettier_action@v1.0
        with:
          prettier_options: "--write {**/*,*}.{js,html,json,md,yml,css,scss}"
          branch: ${{ github.head_ref || github.ref }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Note the branch name: ${{ github.head_ref || github.ref }}.

@creyD
Copy link
Owner

creyD commented Jan 17, 2020

I think you could do this with an if statement in your code. ${{ github.head_ref || github.ref }} won't work, but if you implement this functionality with a if else statement, it should work!

@adriaandotcom
Copy link
Author

Thanks, will try!

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

No branches or pull requests

2 participants