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

feat: add config for running in a date window #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fryz
Copy link

@fryz fryz commented Nov 22, 2022

Description

Add a startDate and endDate parameters, which are used to configure the behavior of executing the auto-comment workflow. Either or both startDate and endDate can be provided, and the current time is checked agains these dates to determine if the workflow can be executed.

The startDate and endDate parameters are not required, and as such, this feature is backwards compatible.

Motivation and Context

I want to support the case where we auto-comment only within a specific date-window. For example, if the company is on a company-wide holiday, I want to configure the auto-commenter to message out that the company is on break and what that means for providing support during this time.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Enhancement (changes that improvement of current feature or performance)
  • Refactoring (changes that neither fixes a bug nor adds a feature)
  • Test Case (changes that add missing tests or correct existing tests)
  • Code style optimization (changes that do not affect the meaning of the code)
  • Docs (changes that only update documentation)
  • Chore (changes that don't modify src or test files)

Self Check before Merge

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@github-actions
Copy link

👋 @fryz
Thank you for raising your pull request.
Please make sure you have followed our contributing guidelines. We will review it as soon as possible

core.info(`Today: ${now}`)

if (!(startDate && startDate < now)) {
throw new Error('Running before StartDate - not executing')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if throwing an error here (and below) is desired behavior (do people monitor workflow executions)?

Happy to refactor this to something better if that's the preferred approach.

Comment on lines +102 to +108
export function getStartDate() {
return new Date(Date.parse(core.getInput('startDate')))
}

export function getEndDate() {
return new Date(Date.parse(core.getInput('endDate')))
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not doing any validation on the input, as Date.parse will return NaN if the format isn't a date.

@fryz
Copy link
Author

fryz commented Nov 23, 2022

For now I've managed to workaround this using a separate step to check the date and fail the workflow if it isn't within the expected range. I'll post this here in case there are others looking to do something similar.

      - name: Checks that current date is between date range
        id: check-dates
        run: |
          today=$(date +'%s')
          start=$(date -d 2022-11-24 +%s)
          end=$(date -d 2022-11-28 +%s)
          if [[ $today -gt $start && $today -lt $end ]] ; then
            exit 0
          else
            exit 1
          fi

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

Successfully merging this pull request may close these issues.

1 participant