From e4cb5fdf516929e64bdbf277b960c1cdbc0fa8ca Mon Sep 17 00:00:00 2001 From: Sachin Panayil Date: Thu, 23 Jan 2025 12:40:47 -0500 Subject: [PATCH] changed workflows trigger Signed-off-by: Sachin Panayil --- .github/workflows/checks.yml | 75 ++++++++++------- .../.github/workflows/checks.yml | 83 +++++++++++-------- .../.github/workflows/checks.yml | 83 +++++++++++-------- .../.github/workflows/checks.yml | 83 +++++++++++-------- .../.github/workflows/checks.yml | 83 +++++++++++-------- 5 files changed, 243 insertions(+), 164 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 561590b..cd33238 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -1,18 +1,58 @@ -name: "run-linting-checks" +name: "Repository Hygiene Check" on: push: branches: - 'main' + workflow_dispatch: jobs: + check-first-run: + name: Check For First Run + runs-on: ubuntu-latest + outputs: + should_run: ${{ steps.check.outputs.should_run }} + permissions: + contents: read + pull-requests: write + steps: + - uses: actions/checkout@v4 + - id: check + run: | + # If manually triggered, always run + + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then + echo "should_run=true" >> $GITHUB_OUTPUT + exit 0 + + fi + + # Check if initialization label exists + + has_label=$(gh label list --json name | jq '.[] | select(.name=="repolinter-initialized")') + + if [[ -z "$has_label" ]]; then + # First time - create label and allow run + gh label create repolinter-initialized --description "Marks repo as having run initial repolinter check" + echo "should_run=true" >> $GITHUB_OUTPUT + else + echo "should_run=false" >> $GITHUB_OUTPUT + + fi + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + resolve-repolinter-json: + name: Get Repolinter Config + needs: check-first-run + if: needs.check-first-run.outputs.should_run == 'true' uses: DSACMS/repo-scaffolder/.github/workflows/extendJSONFile.yml@main with: url_to_json: 'https://raw.githubusercontent.com/DSACMS/repo-scaffolder/main/tier3/%7B%7Bcookiecutter.project_slug%7D%7D/repolinter.json' repolinter-checks: name: Tier 3 Checks - needs: resolve-repolinter-json + needs: [check-first-run, resolve-repolinter-json] + if: needs.check-first-run.outputs.should_run == 'true' runs-on: ubuntu-latest permissions: contents: write @@ -20,39 +60,10 @@ jobs: env: RAW_JSON: ${{ needs.resolve-repolinter-json.outputs.raw-json }} steps: - - uses: actions/checkout@v4 - run: echo $RAW_JSON > repolinter.json - uses: DSACMS/repolinter-action@main with: - # A path to the JSON/YAML Repolinter ruleset to use, relative to the workflow - # working directory (i.e. under `$GITHUB_WORKSPACE`). - # - # This option is mutually exclusive with config_url. If this option and - # config_url are not specified, Repolinter's default ruleset will be used. config_file: 'repolinter.json' - - # Where repolinter-action should put the linting results. There are two - # options available: - # * "exit-code": repolinter-action will print the lint output to the console - # and set the exit code to result.passed. This output type is most useful for - # PR status checks. - # * "issue": repolinter-action will create a GitHub issue on the current - # repository with the repolinter output and always exit 0. See the README for - # more details on issue outputting behavior. This output type is ideal for - # non-intrusive notification. - # - # Default: "exit-code" output_type: 'pull-request' - - # The title to use for the issue created by repolinter-action. This title - # should indicate the purpose of the issue, as well as that it was created by - # a bot. - # - # This option will be ignored if output_type != "issue". - # - # Default: "[Repolinter] Open Source Policy Issues" - pull_request_labels: 'repolinter, cms-oss, cms-gov' - - # The default token is the repolinter token for the DSACMS org - # You can change it if needed. + pull_request_labels: 'repolinter-initialized, cms-oss, cms-gov' token: ${{ secrets.REPOLINTER_AUTO_TOKEN }} diff --git a/tier1/{{cookiecutter.project_slug}}/.github/workflows/checks.yml b/tier1/{{cookiecutter.project_slug}}/.github/workflows/checks.yml index 6029230..f6e6ab5 100644 --- a/tier1/{{cookiecutter.project_slug}}/.github/workflows/checks.yml +++ b/tier1/{{cookiecutter.project_slug}}/.github/workflows/checks.yml @@ -1,18 +1,64 @@ -name: "run-linting-checks" +name: "Repository Hygiene Check" on: push: branches: - 'main' + workflow_dispatch: jobs: + check-first-run: + name: Check For First Run + runs-on: ubuntu-latest + outputs: + {% raw %} + should_run: ${{ steps.check.outputs.should_run }} + {% endraw %} + permissions: + contents: read + pull-requests: write + steps: + - uses: actions/checkout@v4 + - id: check + run: | + # If manually triggered, always run + {% raw %} + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then + {% endraw %} + echo "should_run=true" >> $GITHUB_OUTPUT + exit 0 + fi + + # Check if initialization label exists + has_label=$(gh label list --json name | jq '.[] | select(.name=="repolinter-initialized")') + + if [[ -z "$has_label" ]]; then + # First time - create label and allow run + gh label create repolinter-initialized --description "Marks repo as having run initial repolinter check" + echo "should_run=true" >> $GITHUB_OUTPUT + else + echo "should_run=false" >> $GITHUB_OUTPUT + fi + env: + {% raw %} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + {% endraw %} + resolve-repolinter-json: + name: Get Repolinter Config + needs: check-first-run + {% raw %} + if: needs.check-first-run.outputs.should_run == 'true' + {% endraw %} uses: DSACMS/repo-scaffolder/.github/workflows/extendJSONFile.yml@main with: url_to_json: 'https://raw.githubusercontent.com/DSACMS/repo-scaffolder/main/tier1/%7B%7Bcookiecutter.project_slug%7D%7D/repolinter.json' repolinter-checks: name: Tier 1 Checks - needs: resolve-repolinter-json + needs: [check-first-run, resolve-repolinter-json] + {% raw %} + if: needs.check-first-run.outputs.should_run == 'true' + {% endraw %} runs-on: ubuntu-latest permissions: contents: write @@ -22,41 +68,12 @@ jobs: RAW_JSON: ${{ needs.resolve-repolinter-json.outputs.raw-json }} {% endraw %} steps: - - uses: actions/checkout@v4 - run: echo $RAW_JSON > repolinter.json - uses: DSACMS/repolinter-action@main with: - # A path to the JSON/YAML Repolinter ruleset to use, relative to the workflow - # working directory (i.e. under `$GITHUB_WORKSPACE`). - # - # This option is mutually exclusive with config_url. If this option and - # config_url are not specified, Repolinter's default ruleset will be used. config_file: 'repolinter.json' - - # Where repolinter-action should put the linting results. There are two - # options available: - # * "exit-code": repolinter-action will print the lint output to the console - # and set the exit code to result.passed. This output type is most useful for - # PR status checks. - # * "issue": repolinter-action will create a GitHub issue on the current - # repository with the repolinter output and always exit 0. See the README for - # more details on issue outputting behavior. This output type is ideal for - # non-intrusive notification. - # - # Default: "exit-code" output_type: 'pull-request' - - # The title to use for the issue created by repolinter-action. This title - # should indicate the purpose of the issue, as well as that it was created by - # a bot. - # - # This option will be ignored if output_type != "issue". - # - # Default: "[Repolinter] Open Source Policy Issues" - pull_request_labels: 'repolinter, cms-oss, cms-gov' - - # The default token is the repolinter token for the DSACMS org - # You can change it if needed. + pull_request_labels: 'repolinter-initialized, cms-oss, cms-gov' {% raw %} token: ${{ secrets.REPOLINTER_AUTO_TOKEN }} - {% endraw %} + {% endraw %} \ No newline at end of file diff --git a/tier2/{{cookiecutter.project_slug}}/.github/workflows/checks.yml b/tier2/{{cookiecutter.project_slug}}/.github/workflows/checks.yml index 6a478ca..4d09aed 100644 --- a/tier2/{{cookiecutter.project_slug}}/.github/workflows/checks.yml +++ b/tier2/{{cookiecutter.project_slug}}/.github/workflows/checks.yml @@ -1,18 +1,64 @@ -name: "run-linting-checks" +name: "Repository Hygiene Check" on: push: branches: - 'main' + workflow_dispatch: jobs: + check-first-run: + name: Check For First Run + runs-on: ubuntu-latest + outputs: + {% raw %} + should_run: ${{ steps.check.outputs.should_run }} + {% endraw %} + permissions: + contents: read + pull-requests: write + steps: + - uses: actions/checkout@v4 + - id: check + run: | + # If manually triggered, always run + {% raw %} + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then + {% endraw %} + echo "should_run=true" >> $GITHUB_OUTPUT + exit 0 + fi + + # Check if initialization label exists + has_label=$(gh label list --json name | jq '.[] | select(.name=="repolinter-initialized")') + + if [[ -z "$has_label" ]]; then + # First time - create label and allow run + gh label create repolinter-initialized --description "Marks repo as having run initial repolinter check" + echo "should_run=true" >> $GITHUB_OUTPUT + else + echo "should_run=false" >> $GITHUB_OUTPUT + fi + env: + {% raw %} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + {% endraw %} + resolve-repolinter-json: + name: Get Repolinter Config + needs: check-first-run + {% raw %} + if: needs.check-first-run.outputs.should_run == 'true' + {% endraw %} uses: DSACMS/repo-scaffolder/.github/workflows/extendJSONFile.yml@main with: url_to_json: 'https://raw.githubusercontent.com/DSACMS/repo-scaffolder/main/tier2/%7B%7Bcookiecutter.project_slug%7D%7D/repolinter.json' repolinter-checks: name: Tier 2 Checks - needs: resolve-repolinter-json + needs: [check-first-run, resolve-repolinter-json] + {% raw %} + if: needs.check-first-run.outputs.should_run == 'true' + {% endraw %} runs-on: ubuntu-latest permissions: contents: write @@ -22,41 +68,12 @@ jobs: RAW_JSON: ${{ needs.resolve-repolinter-json.outputs.raw-json }} {% endraw %} steps: - - uses: actions/checkout@v4 - run: echo $RAW_JSON > repolinter.json - uses: DSACMS/repolinter-action@main with: - # A path to the JSON/YAML Repolinter ruleset to use, relative to the workflow - # working directory (i.e. under `$GITHUB_WORKSPACE`). - # - # This option is mutually exclusive with config_url. If this option and - # config_url are not specified, Repolinter's default ruleset will be used. config_file: 'repolinter.json' - - # Where repolinter-action should put the linting results. There are two - # options available: - # * "exit-code": repolinter-action will print the lint output to the console - # and set the exit code to result.passed. This output type is most useful for - # PR status checks. - # * "issue": repolinter-action will create a GitHub issue on the current - # repository with the repolinter output and always exit 0. See the README for - # more details on issue outputting behavior. This output type is ideal for - # non-intrusive notification. - # - # Default: "exit-code" output_type: 'pull-request' - - # The title to use for the issue created by repolinter-action. This title - # should indicate the purpose of the issue, as well as that it was created by - # a bot. - # - # This option will be ignored if output_type != "issue". - # - # Default: "[Repolinter] Open Source Policy Issues" - pull_request_labels: 'repolinter, cms-oss, cms-gov' - - # The default token is the repolinter token for the DSACMS org - # You can change it if needed. + pull_request_labels: 'repolinter-initialized, cms-oss, cms-gov' {% raw %} token: ${{ secrets.REPOLINTER_AUTO_TOKEN }} - {% endraw %} + {% endraw %} \ No newline at end of file diff --git a/tier3/{{cookiecutter.project_slug}}/.github/workflows/checks.yml b/tier3/{{cookiecutter.project_slug}}/.github/workflows/checks.yml index 407cc4a..baba434 100644 --- a/tier3/{{cookiecutter.project_slug}}/.github/workflows/checks.yml +++ b/tier3/{{cookiecutter.project_slug}}/.github/workflows/checks.yml @@ -1,18 +1,64 @@ -name: "run-linting-checks" +name: "Repository Hygiene Check" on: push: branches: - 'main' + workflow_dispatch: jobs: + check-first-run: + name: Check For First Run + runs-on: ubuntu-latest + outputs: + {% raw %} + should_run: ${{ steps.check.outputs.should_run }} + {% endraw %} + permissions: + contents: read + pull-requests: write + steps: + - uses: actions/checkout@v4 + - id: check + run: | + # If manually triggered, always run + {% raw %} + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then + {% endraw %} + echo "should_run=true" >> $GITHUB_OUTPUT + exit 0 + fi + + # Check if initialization label exists + has_label=$(gh label list --json name | jq '.[] | select(.name=="repolinter-initialized")') + + if [[ -z "$has_label" ]]; then + # First time - create label and allow run + gh label create repolinter-initialized --description "Marks repo as having run initial repolinter check" + echo "should_run=true" >> $GITHUB_OUTPUT + else + echo "should_run=false" >> $GITHUB_OUTPUT + fi + env: + {% raw %} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + {% endraw %} + resolve-repolinter-json: + name: Get Repolinter Config + needs: check-first-run + {% raw %} + if: needs.check-first-run.outputs.should_run == 'true' + {% endraw %} uses: DSACMS/repo-scaffolder/.github/workflows/extendJSONFile.yml@main with: url_to_json: 'https://raw.githubusercontent.com/DSACMS/repo-scaffolder/main/tier3/%7B%7Bcookiecutter.project_slug%7D%7D/repolinter.json' repolinter-checks: name: Tier 3 Checks - needs: resolve-repolinter-json + needs: [check-first-run, resolve-repolinter-json] + {% raw %} + if: needs.check-first-run.outputs.should_run == 'true' + {% endraw %} runs-on: ubuntu-latest permissions: contents: write @@ -22,41 +68,12 @@ jobs: RAW_JSON: ${{ needs.resolve-repolinter-json.outputs.raw-json }} {% endraw %} steps: - - uses: actions/checkout@v4 - run: echo $RAW_JSON > repolinter.json - uses: DSACMS/repolinter-action@main with: - # A path to the JSON/YAML Repolinter ruleset to use, relative to the workflow - # working directory (i.e. under `$GITHUB_WORKSPACE`). - # - # This option is mutually exclusive with config_url. If this option and - # config_url are not specified, Repolinter's default ruleset will be used. config_file: 'repolinter.json' - - # Where repolinter-action should put the linting results. There are two - # options available: - # * "exit-code": repolinter-action will print the lint output to the console - # and set the exit code to result.passed. This output type is most useful for - # PR status checks. - # * "issue": repolinter-action will create a GitHub issue on the current - # repository with the repolinter output and always exit 0. See the README for - # more details on issue outputting behavior. This output type is ideal for - # non-intrusive notification. - # - # Default: "exit-code" output_type: 'pull-request' - - # The title to use for the issue created by repolinter-action. This title - # should indicate the purpose of the issue, as well as that it was created by - # a bot. - # - # This option will be ignored if output_type != "issue". - # - # Default: "[Repolinter] Open Source Policy Issues" - pull_request_labels: 'repolinter, cms-oss, cms-gov' - - # The default token is the repolinter token for the DSACMS org - # You can change it if needed. + pull_request_labels: 'repolinter-initialized, cms-oss, cms-gov' {% raw %} token: ${{ secrets.REPOLINTER_AUTO_TOKEN }} - {% endraw %} + {% endraw %} \ No newline at end of file diff --git a/tier4/{{cookiecutter.project_slug}}/.github/workflows/checks.yml b/tier4/{{cookiecutter.project_slug}}/.github/workflows/checks.yml index 237d3a3..8031d7d 100644 --- a/tier4/{{cookiecutter.project_slug}}/.github/workflows/checks.yml +++ b/tier4/{{cookiecutter.project_slug}}/.github/workflows/checks.yml @@ -1,18 +1,64 @@ -name: "run-linting-checks" +name: "Repository Hygiene Check" on: push: branches: - 'main' + workflow_dispatch: jobs: + check-first-run: + name: Check For First Run + runs-on: ubuntu-latest + outputs: + {% raw %} + should_run: ${{ steps.check.outputs.should_run }} + {% endraw %} + permissions: + contents: read + pull-requests: write + steps: + - uses: actions/checkout@v4 + - id: check + run: | + # If manually triggered, always run + {% raw %} + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then + {% endraw %} + echo "should_run=true" >> $GITHUB_OUTPUT + exit 0 + fi + + # Check if initialization label exists + has_label=$(gh label list --json name | jq '.[] | select(.name=="repolinter-initialized")') + + if [[ -z "$has_label" ]]; then + # First time - create label and allow run + gh label create repolinter-initialized --description "Marks repo as having run initial repolinter check" + echo "should_run=true" >> $GITHUB_OUTPUT + else + echo "should_run=false" >> $GITHUB_OUTPUT + fi + env: + {% raw %} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + {% endraw %} + resolve-repolinter-json: + name: Get Repolinter Config + needs: check-first-run + {% raw %} + if: needs.check-first-run.outputs.should_run == 'true' + {% endraw %} uses: DSACMS/repo-scaffolder/.github/workflows/extendJSONFile.yml@main with: url_to_json: 'https://raw.githubusercontent.com/DSACMS/repo-scaffolder/main/tier4/%7B%7Bcookiecutter.project_slug%7D%7D/repolinter.json' repolinter-checks: name: Tier 4 Checks - needs: resolve-repolinter-json + needs: [check-first-run, resolve-repolinter-json] + {% raw %} + if: needs.check-first-run.outputs.should_run == 'true' + {% endraw %} runs-on: ubuntu-latest permissions: contents: write @@ -22,41 +68,12 @@ jobs: RAW_JSON: ${{ needs.resolve-repolinter-json.outputs.raw-json }} {% endraw %} steps: - - uses: actions/checkout@v4 - run: echo $RAW_JSON > repolinter.json - uses: DSACMS/repolinter-action@main with: - # A path to the JSON/YAML Repolinter ruleset to use, relative to the workflow - # working directory (i.e. under `$GITHUB_WORKSPACE`). - # - # This option is mutually exclusive with config_url. If this option and - # config_url are not specified, Repolinter's default ruleset will be used. config_file: 'repolinter.json' - - # Where repolinter-action should put the linting results. There are two - # options available: - # * "exit-code": repolinter-action will print the lint output to the console - # and set the exit code to result.passed. This output type is most useful for - # PR status checks. - # * "issue": repolinter-action will create a GitHub issue on the current - # repository with the repolinter output and always exit 0. See the README for - # more details on issue outputting behavior. This output type is ideal for - # non-intrusive notification. - # - # Default: "exit-code" output_type: 'pull-request' - - # The title to use for the issue created by repolinter-action. This title - # should indicate the purpose of the issue, as well as that it was created by - # a bot. - # - # This option will be ignored if output_type != "issue". - # - # Default: "[Repolinter] Open Source Policy Issues" - pull_request_labels: 'repolinter, cms-oss, cms-gov' - - # The default token is the repolinter token for the DSACMS org - # You can change it if needed. + pull_request_labels: 'repolinter-initialized, cms-oss, cms-gov' {% raw %} token: ${{ secrets.REPOLINTER_AUTO_TOKEN }} - {% endraw %} + {% endraw %} \ No newline at end of file