From 8c7733d9d003d47430044b89606352286e305745 Mon Sep 17 00:00:00 2001 From: Florian Bernd Date: Mon, 17 Jul 2023 11:00:36 +0200 Subject: [PATCH] Automatically compile/generate output artifacts on push to `main` (#2181) --- .github/workflows/generate.yml | 92 ++++++++++++++++++++++++++++++ .github/workflows/output-check.yml | 34 ----------- 2 files changed, 92 insertions(+), 34 deletions(-) create mode 100644 .github/workflows/generate.yml delete mode 100644 .github/workflows/output-check.yml diff --git a/.github/workflows/generate.yml b/.github/workflows/generate.yml new file mode 100644 index 0000000000..4a6a119cbd --- /dev/null +++ b/.github/workflows/generate.yml @@ -0,0 +1,92 @@ +name: Generate Output + +on: + push: + branches: + - 'main' + - '7.17' + - '8.[0-9]+' + + # For debugging purposes: + # pull_request: + # types: [opened, synchronize, reopened] + # branches: + # - main + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: false + +defaults: + run: + shell: bash + +jobs: + build: + runs-on: ubuntu-latest + if: github.repository_owner == 'elastic' && github.actor != 'elasticmachine' + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + token: ${{ secrets.PAT }} + persist-credentials: true + + - name: Setup Node 16.x + uses: actions/setup-node@v3 + with: + node-version: 16.x + cache: npm + cache-dependency-path: '**/package-lock.json' + + - name: Setup Dependencies + run: | + make setup + + - name: Generate Output + run: | + make compile + make generate + + - name: Check for Changed Files + id: changes + run: | + if [ -n "$(git status --porcelain)" ]; then + echo "has-changes=1" >> $GITHUB_OUTPUT + fi + + - name: Set Git Identity + if: steps.changes.outputs.has-changes == '1' + run: |- + git config --global user.email "elasticmachine@users.noreply.github.com" + git config --global user.name "Elastic Machine" + + - name: Push Output + if: steps.changes.outputs.has-changes == '1' + run: | + cd ./output + + git add -A + git commit -m "Update specification output" + + git status + + git push + + # For debugging purposes: + # - name: Push Output + # if: steps.changes.outputs.has-changes == '1' + # env: + # BRANCH_NAME: output_${{ github.run_id }}_${{ github.run_attempt }} + # run: | + # cd ./output + + # git fetch + # git switch main + + # git add -A + # git commit -m "Update specification output" + + # git status + + # git push origin HEAD:refs/heads/${{ env.BRANCH_NAME }} diff --git a/.github/workflows/output-check.yml b/.github/workflows/output-check.yml deleted file mode 100644 index 4e112886dd..0000000000 --- a/.github/workflows/output-check.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Check output freshness - -on: [pull_request] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Use Node.js 16.x - uses: actions/setup-node@v1 - with: - node-version: 16.x - - - name: Install - run: | - npm install --prefix compiler - npm install --prefix typescript-generator - - - name: Generate output - run: | - make generate - npm run start --prefix typescript-generator - - - name: Validate TS output - run: | - npm run validate-ts-view --prefix compiler - - - name: Check freshness - run: | - if [ -n "$(git status --porcelain)" ]; then echo Error: changes found after running the generation; git diff; git status; exit 1; fi