diff --git a/.github/workflows/global-replicator.yml b/.github/workflows/global-replicator.yml index 626cb443..df0b23f3 100644 --- a/.github/workflows/global-replicator.yml +++ b/.github/workflows/global-replicator.yml @@ -161,4 +161,22 @@ jobs: committer_username: asyncapi-bot committer_email: info@asyncapi.io commit_message: "ci: update of files from global .github repo" - bot_branch_name: bot/update-files-from-global-repo \ No newline at end of file + bot_branch_name: bot/update-files-from-global-repo + + replicate_validate_workflow_schema: + if: startsWith(github.repository, 'asyncapi/') + name: Replicate workflow schema validation to repositories + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Replicating file + uses: derberg/manage-files-in-multiple-repositories@beecbe897cf5ed7f3de5a791a3f2d70102fe7c25 + with: + github_token: ${{ secrets.GH_TOKEN }} + patterns_to_include: .github/workflows/validate-workflow-schema.yml + topics_to_include: get-workflows-validation + committer_username: asyncapi-bot + committer_email: info@asyncapi.io + commit_message: "ci: update of files from global .github repo" + bot_branch_name: bot/update-files-from-global-repo \ No newline at end of file diff --git a/.github/workflows/if-nodejs-release.yml b/.github/workflows/if-nodejs-release.yml index 6f7db575..4938a37d 100644 --- a/.github/workflows/if-nodejs-release.yml +++ b/.github/workflows/if-nodejs-release.yml @@ -101,7 +101,7 @@ jobs: run: npm install - if: steps.packagejson.outputs.exists == 'true' name: Add plugin for conventional commits for semantic-release - run: npm install conventional-changelog-conventionalcommits@5.0.0 + run: npm install --save-dev conventional-changelog-conventionalcommits@5.0.0 - if: steps.packagejson.outputs.exists == 'true' name: Publish to any of NPM, Github, and Docker Hub id: release @@ -123,4 +123,4 @@ jobs: fields: repo,action,workflow text: 'Release workflow failed in release job' env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CI_FAIL_NOTIFY }} \ No newline at end of file + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CI_FAIL_NOTIFY }} diff --git a/.github/workflows/validate-workflow-schema.yml b/.github/workflows/validate-workflow-schema.yml new file mode 100644 index 00000000..d13d3680 --- /dev/null +++ b/.github/workflows/validate-workflow-schema.yml @@ -0,0 +1,72 @@ +name: YAML Lint Check + +on: + pull_request: + branches: + - master + paths: + - '.github/workflows/**' + +jobs: + yaml-lint: + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v2 + + - name: Install Dependencies + run: npm install yaml-lint ajv axios js-yaml + + - name: Lint YAML Files + run: | + set -e + find .github/workflows -type f -name "*.yml" -print0 | xargs -0 ./node_modules/.bin/yamllint -q + + - name: List YAML files to validate + run: | + set -e + files=$(find .github/workflows -name '*.yml') + echo "Validating the following files:" + echo "$files" + + - name: Run YAML validation + uses: actions/github-script@v6 + with: + script: | + const Ajv = require("ajv"); + const axios = require("axios"); + const yaml = require("js-yaml"); + const fs = require("fs").promises; + + async function validateWorkflows() { + const schema = await axios.get( + "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/github-workflow.json" + ); + + const files = await fs.readdir(".github/workflows"); + const ymlFiles = files.filter((file) => file.endsWith(".yml")); + + for (const file of ymlFiles) { + try { + const content = await fs.readFile(`.github/workflows/${file}`, "utf8"); + const target = yaml.load(content); + + const ajv = new Ajv({ strict: false, allErrors: true }); + const validator = ajv.compile(schema.data); + const valid = validator(target); + if (!valid) { + console.error( + `Validation failed for file '${file}' with the following errors:` + ); + console.error(validator.errors); + process.exitCode = 1; + } else { + console.log(`Workflow in file '${file}' is valid`); + } + } catch (error) { + console.error(`Error validating file '${file}': ${error.message}`); + process.exitCode = 1; + } + } + } + validateWorkflows(); \ No newline at end of file diff --git a/README.md b/README.md index 4b33d40a..a6b56c8b 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,13 @@ The purpose of this repository is to keep all the community health files that we would normally have to duplicate in each repository. These are global community files that apply to repositories that do not have their own files. + +Below is a list of workflows with their corresponding topics and descriptions. By including each topic in your repository in AsyncAPI organisation, you will subscribe to get a workflow or a group of workflows that perform a specific task. + +| Topic to include | Workflows you will get | Description | +| --- | --- | --- | +| `get-workflows-validation` | [validate-workflow-schema](.github/workflows/validate-workflow-schema.yml) | Validates the YAML schema of a workflow files in your repository +| `golang` | [if-go-pr-testing](.github/workflows/if-go-pr-testing.yml) | Compiles and tests Go code using multiple versions of Go +| `nodejs` | [if-nodejs-pr-testing](.github/workflows/if-nodejs-pr-testing.yml) | Builds and tests Node.js projects using multiple Node.js versions +| `get-global-node-release-workflows` | [if-nodejs-release](.github/workflows/if-nodejs-release.yml), [if-nodejs-version-bump.yml](.github/workflows/if-nodejs-version-bump.yml) , [bump.yml](.github/workflows/bump.yml) | Fetches and publishes Node.js release information to the project's website +| `get-global-releaserc` | [.releaserc](.github/workflows/.releaserc) | Fetches release configuration files from a remote repository and makes them available to other workflows \ No newline at end of file