From ae9e68e2d8ac7f6e596b1bca8ddb8e467e3b75cb Mon Sep 17 00:00:00 2001 From: Tomas Sebestik Date: Fri, 6 Sep 2024 12:51:56 +0200 Subject: [PATCH] change(action-yml): set inputs with defaults instead environment variables --- action.yml | 48 ++++++++++++++++++++++--------- sync_jira_actions/sync_to_jira.py | 7 ++++- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/action.yml b/action.yml index dd055ac..d6efb13 100644 --- a/action.yml +++ b/action.yml @@ -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: ` + or as an environment variable `ENV: JIRA_PROJECT: ` (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' @@ -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 @@ -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: ` or as `ENV:JIRA_PROJECT: ` + JIRA_COMPONENT: ${{ inputs.jira-component }} # Optional + JIRA_ISSUE_TYPE: ${{ inputs.jira-issue-type }} # Optional diff --git a/sync_jira_actions/sync_to_jira.py b/sync_jira_actions/sync_to_jira.py index f01ffd2..607990a 100755 --- a/sync_jira_actions/sync_to_jira.py +++ b/sync_jira_actions/sync_to_jira.py @@ -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...') @@ -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