GitHub Actionsでファイルの存在や内容をチェックする

Standard

.github/workflows/filecheck.yml

name: "File Check"

on: [push, pull_request]

jobs:
  file_check:
    runs-on: ubuntu-latest
    name: file check
    steps:
      - name: Checkout code
        uses: actions/[email protected]

      - name: Check file existence
        id: check_files
        uses: andstor/[email protected]
        with:
          files: "README.txt"
      - name: File exists
        if: steps.check_files.outputs.files_exists != 'true'
        run: |
          exit 1

      - name: Read file
        id: package
        uses: juliangruber/[email protected]
        with:
          path: ./README.txt
      - name: Echo file
        run: echo "${{ steps.package.outputs.content }}"
      - name: If file contains
        if: contains(steps.package.outputs.content, 'stop!')
        run: |
          exit 1

      - name: Validate YAML
        uses: brittonhayes/[email protected]
        with:
          schemaPath: ".github/data/validate-yaml.json"
          files: |
            test.yaml

.github/data/validate-yaml.json

{
  "test": {
    "structure": {
      "myValue": "string",
      "myValue2": "string"
    }
  }
}

test.yaml

test:
  structure:
    myValue: '1'
    myValue2: '2'

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.