Skip to content

Commit

Permalink
change(action-yml): set inputs with defaults instead environment vari…
Browse files Browse the repository at this point in the history
…ables
  • Loading branch information
tomassebestik committed Sep 6, 2024
1 parent 8df27b7 commit ae9e68e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
48 changes: 35 additions & 13 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
---
name: Sync GitHub Issues to JIRA
description: 'Performs simple one way syncing of GitHub issues into JIRA.'

branding:
icon: 'fast-forward'
color: 'green'
name: Sync GitHub Pull requests and Issues to JIRA
description: >
Synchronizes Issues, Issue comments and Pull Requests from Espressif GitHub to Espressif JIRA.
inputs:
cron_job:
cron-job:
description: >
THIS INPUT IS INCLUDED ONLY FOR COMPATIBILITY WITH LEGACY CALLER WORKFLOWS.
ALL LOGIC IS DETERMINED BASED ON THE ACTION TRIGGER.
Indicates whether the action is being run as a scheduled cron job
If so, the it syncs new pull requests during the cron job execution.
jira-project:
description: >
Whether the action is run as a cron job.
Set true to trigger syncing of new PRs.
required: false
The key of the JIRA project where issues will be created or updated.
It can be passed either as an input `with: jira-project: <jira_key>`
or as an environment variable `ENV: JIRA_PROJECT: <jira_key>` (legacy).
If this is not passed one way or another, a check in the sync script will cause the action to fail.
jira-component:
description: 'The JIRA component to which the issues will be assigned.'
default: 'GitHub'

jira-issue-type:
description: 'The type of JIRA issue to be created if no labels to the issue are set'
default: 'Task'

runs:
using: 'composite'
Expand All @@ -29,12 +42,12 @@ runs:
cache: 'pip'

- name: Install Python dependencies
shell: bash
run: |
python -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
shell: bash
- name: Install Node.js
uses: actions/setup-node@v4
Expand All @@ -43,11 +56,20 @@ runs:
cache: 'npm'

- name: Install npm dependencies (markdown2confluence)
run: npm ci
shell: bash
run: npm ci

- name: Run sync_to_jira.py
shell: bash
run: |
source venv/bin/activate
python sync_jira_actions/sync_to_jira.py
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # No need to pass as input or ENV, GITHUB_TOKEN is always available by default
INPUT_CRON_JOB: ${{ github.event_name == 'schedule' && 'true' || '' }} # No need to pass as input or ENV, set based on action trigger
JIRA_PASS: ${{ secrets.JIRA_PASS }} # No need to pass as input or ENV, set as secret at the organization level
JIRA_URL: ${{ secrets.JIRA_URL }} # No need to pass as input or ENV, set as secret at the organization level
JIRA_USER: ${{ secrets.JIRA_USER }} # No need to pass as input or ENV, set as secret at the organization level
JIRA_PROJECT: ${{ inputs.jira-project }} # Pass as input `with:jira-project: <jira_key>` or as `ENV:JIRA_PROJECT: <jira_key>`
JIRA_COMPONENT: ${{ inputs.jira-component }} # Optional
JIRA_ISSUE_TYPE: ${{ inputs.jira-issue-type }} # Optional
7 changes: 6 additions & 1 deletion sync_jira_actions/sync_to_jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ def main():
print('Not an Espressif repo, nothing to sync to JIRA')
return

# For backward compatibility; handles situation if JIRA_PROJECT is not set in caller workflow either as input or ENV
if 'JIRA_PROJECT' not in os.environ:
print('JIRA_PROJECT not set, fail!')
raise SystemExit(1)

# Connect to Jira server
print('Connecting to Jira Server...')

Expand All @@ -61,7 +66,7 @@ def main():
jira = _JIRA(os.environ['JIRA_URL'], basic_auth=(os.environ['JIRA_USER'], token_or_pass))

# Check if it's a cron job
if os.environ.get('INPUT_CRON_JOB'):
if os.environ.get('INPUT_CRON_JOB') == 'true':
print('Running as a cron job. Syncing remaining PRs...')
sync_remain_prs(jira)
return
Expand Down

0 comments on commit ae9e68e

Please sign in to comment.