From 640902e423687550a9384c50b7c6782100e83c42 Mon Sep 17 00:00:00 2001 From: Alexandre Faria <16895682+lusoalex@users.noreply.github.com> Date: Tue, 27 Aug 2019 18:54:12 +0200 Subject: [PATCH] feat: converted main.workflow to Actions V2 yml files (#19) Switch to GitHub Actions V2 syntax (YAML) and fix neutral exit code to succeed when nothing to do. --- .github/main.workflow | 45 ---------------------- .github/workflows/milestone.yml | 27 +++++++++++++ .github/workflows/pull_request.yml | 13 +++++++ README.md | 62 ++++++++++++++++++++++++++---- src/entrypoint.ts | 9 +++-- 5 files changed, 99 insertions(+), 57 deletions(-) delete mode 100644 .github/main.workflow create mode 100644 .github/workflows/milestone.yml create mode 100644 .github/workflows/pull_request.yml diff --git a/.github/main.workflow b/.github/main.workflow deleted file mode 100644 index 25bafd0..0000000 --- a/.github/main.workflow +++ /dev/null @@ -1,45 +0,0 @@ -workflow "Auto Label Pull Request" { - resolves = ["PR label by Files"] - on = "pull_request" -} - -action "PR label by Files" { - uses = "./" - secrets = ["GITHUB_TOKEN"] -} - -workflow "Milestone Closure" { - on = "milestone" - resolves = ["Upload Release Notes to Wiki"] -} - -action "action-filter" { - uses = "actions/bin/filter@master" - args = "action closed" -} - -action "Create Release Notes" { - uses = "docker://decathlon/release-notes-generator-action:1.0.1" - secrets = ["GITHUB_TOKEN"] - needs = ["action-filter"] - env = { - USE_MILESTONE_TITLE = "true" - OUTPUT_FOLDER = "temp_release_notes" - } -} - -action "Upload Release Notes to Wiki" { - uses = "docker://decathlon/wiki-page-creator-action:1.0.0" - needs = ["Create Release Notes"] - secrets = [ - "GH_PAT", - ] - env = { - ACTION_MAIL = "oss@decathlon.com" - ACTION_NAME = "decathlonbot" - OWNER = "decathlon" - REPO_NAME = "pull-request-labeler-action" - SKIP_MD = "README.md" - MD_FOLDER = "temp_release_notes" - } -} diff --git a/.github/workflows/milestone.yml b/.github/workflows/milestone.yml new file mode 100644 index 0000000..90b920a --- /dev/null +++ b/.github/workflows/milestone.yml @@ -0,0 +1,27 @@ +on: milestone +name: Milestone Closure +jobs: + action-filter: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@master + - name: action-filter + uses: actions/bin/filter@master + with: + args: action closed + - name: Create Release Notes + uses: docker://decathlon/release-notes-generator-action:1.0.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OUTPUT_FOLDER: temp_release_notes + USE_MILESTONE_TITLE: "true" + - name: Upload Release Notes to Wiki + uses: docker://decathlon/wiki-page-creator-action:1.0.0 + env: + ACTION_MAIL: oss@decathlon.com + ACTION_NAME: decathlonbot + GH_PAT: ${{ secrets.GH_PAT }} + MD_FOLDER: temp_release_notes + OWNER: decathlon + REPO_NAME: pull-request-labeler-action + SKIP_MD: README.md diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 0000000..76996c9 --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,13 @@ +on: pull_request +name: Auto Label Pull Request +jobs: + pRLabelByFiles: + name: PR label by Files + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@master + - name: PR label by Files + uses: ./ + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CONFIG_PATH: ${{ secrets.GITHUB_WORKSPACE }}/.github/label-pr.yml diff --git a/README.md b/README.md index ea8b0ff..11a3773 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,26 @@ -# Github auto-labeler action -[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FDecathlon%2Fpull-request-labeler-action.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2FDecathlon%2Fpull-request-labeler-action?ref=badge_shield) -[![CircleCI](https://circleci.com/gh/Decathlon/pull-request-labeler-action/tree/master.svg?style=svg)](https://circleci.com/gh/Decathlon/pull-request-labeler-action/tree/master) - -GitHub actions to auto label a pull request based on committed files. -

- Result illustration + Result illustration
+ + +

+ This repository provides a GitHub action to automatically label a pull request based on committed files.

+**Table of Contents** + +- [Common usage](#common-usage) +- [Breaking change](#breaking-change) +- [Startup](#startup) + - [Configuration](#configuration) + - [Use Github action](#use-github-action) + - [Settings for v1.0.0+ release (deprecated)](#settings-for-v100-release-deprecated) + - [Settings for v2.0.0+ release](#settings-for-v200-release) +- [Contributing](#contributing) + - [Commands](#commands) +- [License](#license) + +## Common usage + When pushing, the action will be triggered and will look for committed files over your branch. It applies configured labels whenever it find a file whose name matches the associated regular expression. @@ -16,6 +29,13 @@ It applies configured labels whenever it find a file whose name matches the asso Action log messages

+## Breaking change + +Starting from August 2019, GitHub switch [Actions syntax from HCL to YAML](https://help.github.com/en/articles/migrating-github-actions-from-hcl-syntax-to-yaml-syntax). +The previous syntax will no longer be supported by GitHub on September 30, 2019. + +As a consequence, __please use v2.0.0+__ release and note that __all v1.x.x are deprecated__ and will no longer work on September 30, 2019. + ## Startup ### Configuration @@ -43,6 +63,8 @@ If the labels do not exist yet in your repository configuration, they will be cr ### Use Github action +#### Settings for v1.0.0+ release (deprecated) + Create a file into your root project directory (if it does not exist yet): `.github/main.workflow`: ``` workflow "New workflow" { @@ -56,7 +78,31 @@ action "PR label by Files" { } ``` -When configuring the action, you need to provide the right link into `uses` field here. +#### Settings for v2.0.0+ release + +Create a file into your root project directory: `.github/workflows/labeler.yml`: +```yaml +# Workflow to associate labels automatically +name: labeler +# Trigger the workflow on pull request events +on: [pull_request] +jobs: + label: + runs-on: ubuntu-18.04 + steps: + # We need to checkout the repository to access the configured file (.github/label-pr.yml) + - uses: actions/checkout@v1 + with: + fetch-depth: 1 + - name: Labeler + uses: docker://decathlon/pull-request-labeler-action:2.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Here we can override the path for the action configuration. If none is provided, default one is `.github/label-pr.yml` + CONFIG_PATH: ${{ secrets.GITHUB_WORKSPACE }}/.github/label-pr.yml +``` + +_Please note that you can move the label-pr.yml to another location, if so, then do not forget to update the above **CONFIG_PATH**_ variable. ## Contributing diff --git a/src/entrypoint.ts b/src/entrypoint.ts index 663f695..eeb133c 100644 --- a/src/entrypoint.ts +++ b/src/entrypoint.ts @@ -72,7 +72,7 @@ const getLabelsToAdd = (labels: string[], issueLabels: string[], {log, exit}: To const labelsToAdd: string[] = intersectLabels(labels, issueLabels); log.info('Labels to add: ', labelsToAdd); if (labelsToAdd.length === 0) { - exit.neutral("No labels to add"); + exit.success("No labels to add"); } return labelsToAdd; }; @@ -96,7 +96,8 @@ Toolkit.run(async (toolkit: Toolkit) => { toolkit.log.info('Open sourced by\n' + LOGO); toolkit.log.info('Running Action'); - const filters: Filter[] = toolkit.config('.github/label-pr.yml'); + const configPath: string = process.env.CONFIG_PATH ? process.env.CONFIG_PATH : '.github/label-pr.yml'; + const filters: Filter[] = toolkit.config(configPath); toolkit.log.info(" Configured filters: ", filters); if (!process.env.GITHUB_EVENT_PATH) { @@ -123,8 +124,8 @@ Toolkit.run(async (toolkit: Toolkit) => { } ) .then((addLabelsParams: IssuesAddLabelsParams) => issues.addLabels(addLabelsParams)) - .then((value: Response) => toolkit.log.info(`Adding label status: ${value.status}`)) - .catch(reason => toolkit.exit.failure(reason)); + .catch(reason => toolkit.exit.failure(reason)) + .then((value: Response) => toolkit.log.info(`Adding label status: ${value.status}`)); } toolkit.exit.success('Labels were update into pull request') },