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

[help] trying to make it work on a scheduled composer update #9

Closed
patrick-leb opened this issue Oct 3, 2022 · 3 comments
Closed

Comments

@patrick-leb
Copy link

hi there!

You action works perfectly on my PR workflow, no problem there.
I'd like to commit a composer update on a schedule. here is my workflow:

'on':
  schedule:
    -
      cron: '24 6 * * 1,2,3,4,5'
  workflow_dispatch: null
jobs:
  composer_update_job:
    runs-on: ubuntu-latest
    name: 'composer update'
    steps:
    
      - name: Get current date
        id: date
        run: echo "::set-output name=date::$(date +'%Y-%m-%d')" 
      -
        name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      -
        name: 'Setup PHP'
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.0'
      -
        name: 'Run composer update'
        run: 'composer update --no-dev --no-progress'
        id: run_composer
        
      - name: Generate composer diff
        id: composer_diff # To reference the output in comment
        uses: IonBazan/composer-diff-action@v1
        with: 
          no-dev: true
          format: mdlist
      -
        name: 'Create Pull Request'
        uses: peter-evans/create-pull-request@v4
        id: cpr
        with:
          token: '${{ secrets.MERGE_TOKEN }}'
          commit-message: ${{ steps.composer_diff.outputs.composer_diff }}
          committer: 'Woogo Bot <noreply@github.com>'
          author: 'Woogo Bot <woogo.bot@users.noreply.github.com>'
          branch: woogobot/composer-update
          delete-branch: true
          title: 'feat(plugins) composer update'
          labels: 'composer update'

The output of ${{ steps.composer_diff.outputs.composer_diff }} is empty there. However in the PR check, it will be correct.

What am I doing wrong here ?

Thanks!

@IonBazan
Copy link
Owner

IonBazan commented Oct 4, 2022

Hi @patrick-leb, I'm glad you enjoy using this GitHub Action on your pipelines.
I think the problem is that base parameter defaults to ${{ github.event.pull_request.base.sha }} which is empty when the action is not triggered by a PR:

base:
description: 'Base composer.lock file path or git ref '
required: true
default: ${{ github.event.pull_request.base.sha }}

When providing an empty string to base, the library concats composer.lock to it, causing a comparison between same file, producing an empty output. You can try setting it to HEAD in your workflow:

      - name: Generate composer diff
        id: composer_diff # To reference the output in comment
        uses: IonBazan/composer-diff-action@v1
        with: 
          base: HEAD
          no-dev: true
          format: mdlist

I hope that helps!

@patrick-leb
Copy link
Author

That fixed it! Amazing!

May I suggest you add this use case to the docs? it will probably help someone else :)

Cheers!

@IonBazan
Copy link
Owner

IonBazan commented Nov 2, 2022

Thanks for the suggestion - added it in the README.md since https://github.com/IonBazan/composer-diff-action/releases/tag/v1.0.6

@IonBazan IonBazan closed this as completed Nov 2, 2022
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

2 participants