diff --git a/.github/workflows/generate.yaml b/.github/workflows/generate.yaml new file mode 100644 index 0000000..fd56fd3 --- /dev/null +++ b/.github/workflows/generate.yaml @@ -0,0 +1,40 @@ +name: generate + +on: + schedule: + - cron: '0 0 * * *' + workflow_dispatch: + +jobs: + run: + runs-on: ubuntu-latest + + steps: + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.0' + + - name: Checkout + uses: actions/checkout@v2 + + - name: Generate + run: make + + - name: Count changes + id: changes + run: | + git add -N . + echo "::set-output name=count::$(git diff --name-only | wc -l)" + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 + with: + commit-message: Update Error Code + delete-branch: true + title: Update Error Code + body: | + Error codes have been updated. + + - https://github.com/postgres/postgres/blob/master/src/backend/utils/errcodes.txt + if: ${{ steps.changes.outputs.count > 0 }} diff --git a/tools/generator.php b/tools/generator.php index f61dd7c..db1ad2e 100644 --- a/tools/generator.php +++ b/tools/generator.php @@ -4,7 +4,10 @@ $const = array(); while ($row = fgets(STDIN)) { - if (preg_match('/^([0-9A-Z]{5}) +[SWE] +[^ ]+? +([a-z_]+)$/', $row, $matches)) { + if (preg_match('/^Section: (Class .*)$/', $row, $matches)) { + $const[] = ''; + $const[] = " // {$matches[1]}"; + } elseif (preg_match('/^([0-9A-Z]{5}) +[SWE] +[^ ]+? +([a-z_]+)$/', $row, $matches)) { $key = strtoupper($matches[2]); if (isset($codes[$key])) { $key .= '_EXCEPTION'; @@ -14,7 +17,7 @@ } } -$const = implode(PHP_EOL, $const); +$const = trim(implode(PHP_EOL, $const), PHP_EOL); echo <<