| 1 | name: VC gen |
| 2 | |
| 3 | on: |
| 4 | workflow_dispatch: |
| 5 | pull_request: |
| 6 | paths-ignore: |
| 7 | - '**.vv' |
| 8 | - '**.out' |
| 9 | - '**.md' |
| 10 | - '**.yml' |
| 11 | - '!**/gen_vc_ci.yml' |
| 12 | - 'cmd/tools/**' |
| 13 | - '!cmd/tools/builders/**.v' |
| 14 | push: |
| 15 | branches: |
| 16 | - master |
| 17 | paths-ignore: |
| 18 | - '**.vv' |
| 19 | - '**.out' |
| 20 | - '**.md' |
| 21 | - '**.yml' |
| 22 | - '!**/gen_vc_ci.yml' |
| 23 | - 'cmd/tools/**' |
| 24 | - '!cmd/tools/builders/**.v' |
| 25 | |
| 26 | # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. |
| 27 | # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. |
| 28 | concurrency: |
| 29 | group: gen_vc-${{ github.workflow }}-${{ github.ref }} |
| 30 | cancel-in-progress: ${{ !contains(github.ref, 'master')}} |
| 31 | |
| 32 | jobs: |
| 33 | build-vc: |
| 34 | runs-on: ubuntu-latest |
| 35 | timeout-minutes: 20 |
| 36 | steps: |
| 37 | - uses: actions/checkout@v6 |
| 38 | - name: Build V |
| 39 | run: make -j4 |
| 40 | - name: Regenerate v.c and v_win.c |
| 41 | run: | |
| 42 | git config --global user.email "[email protected]" |
| 43 | git config --global user.name "vlang-bot" |
| 44 | |
| 45 | COMMIT_HASH="$(git rev-parse HEAD)" |
| 46 | COMMIT_MSG="$(git log -1 --oneline --pretty='%s' HEAD)" |
| 47 | |
| 48 | rm -rf vc |
| 49 | ./v retry -- git clone --depth=1 "https://vlang-bot:${{ secrets.VLANG_BOT_SECRET }}@github.com/vlang/vc.git" |
| 50 | |
| 51 | rm -rf vc/v.c vc/v_win.c |
| 52 | ./v -o vc/v.c -cross cmd/v |
| 53 | ./v -o vc/v_win.c -os windows -cc msvc cmd/v |
| 54 | |
| 55 | sed -i "1s/^/#define V_COMMIT_HASH \"$COMMIT_HASH\"\n/" vc/v.c |
| 56 | sed -i "1s/^/#define V_COMMIT_HASH \"$COMMIT_HASH\"\n/" vc/v_win.c |
| 57 | |
| 58 | # do some sanity checks for the generated v.c file: |
| 59 | grep 'Turned ON custom defines: no_backtrace,cross' vc/v.c |
| 60 | grep '#define CUSTOM_DEFINE_cross' vc/v.c |
| 61 | |
| 62 | # ensure the generated C files for the compiler, are over 5000 lines long, as a safety measure |
| 63 | [ "$(wc -l < vc/v.c)" -gt 5000 ] |
| 64 | [ "$(wc -l < vc/v_win.c)" -gt 5000 ] |
| 65 | |
| 66 | git -C vc add v.c v_win.c |
| 67 | git -C vc commit -m "[v:master] $COMMIT_HASH - $COMMIT_MSG" |
| 68 | |
| 69 | # in case there are recent commits: |
| 70 | ./v retry -- git -C vc pull --rebase origin master |
| 71 | git -C vc log -3 |
| 72 | |
| 73 | - name: Deploy |
| 74 | if: github.event_name == 'push' && github.repository == 'vlang/v' && github.ref == 'refs/heads/master' |
| 75 | run: git -C vc push || true |
| 76 | |