|
1 | | -name: Cross-Platform Build and Release |
| 1 | +name: Cross-Compile & Release |
2 | 2 |
|
3 | 3 | on: |
4 | | - # Trigger every 15 minutes and on manual dispatch. |
5 | | - schedule: |
6 | | - - cron: '*/15 * * * *' |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
7 | 7 | workflow_dispatch: |
8 | 8 |
|
9 | 9 | jobs: |
10 | | - # ----------------------------------------------------------- |
11 | | - # 1. Sync the upstream source into the mirror repository. |
12 | | - # ----------------------------------------------------------- |
13 | | - git-sync: |
14 | | - runs-on: ubuntu-latest |
15 | | - outputs: |
16 | | - # (optional: you could output the path if needed by downstream jobs) |
17 | | - synced: true |
| 10 | + build: |
| 11 | + strategy: |
| 12 | + matrix: |
| 13 | + os: [ubuntu-latest, windows-latest] |
| 14 | + runs-on: ${{ matrix.os }} |
18 | 15 | steps: |
19 | | - - name: Sync repositories |
20 | | - uses: wei/git-sync@v3 |
21 | | - with: |
22 | | - source_repo: "https://repo.or.cz/tinycc.git" |
23 | | - source_branch: "mob" |
24 | | - destination_repo: "git@github.com:Tiny-C-Compiler/mirror-repository" |
25 | | - destination_branch: "mob" |
26 | | - ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} |
27 | | - |
28 | | - # ----------------------------------------------------------- |
29 | | - # 2. Build the Linux binary on Ubuntu. |
30 | | - # ----------------------------------------------------------- |
31 | | - build-linux: |
32 | | - needs: git-sync |
33 | | - runs-on: ubuntu-latest |
34 | | - steps: |
35 | | - - name: Checkout mirror repository |
36 | | - uses: actions/checkout@v4 |
37 | | - with: |
38 | | - repository: Tiny-C-Compiler/mirror-repository |
39 | | - ref: mob |
40 | | - ssh-key: ${{ secrets.SSH_PRIVATE_KEY }} |
41 | | - fetch-depth: 0 |
| 16 | + - name: Checkout source |
| 17 | + uses: actions/checkout@v3 |
42 | 18 |
|
43 | | - - name: Install Linux build dependencies |
| 19 | + # --- Setup build dependencies |
| 20 | + - name: Setup Linux build tools |
| 21 | + if: matrix.os == 'ubuntu-latest' |
44 | 22 | run: | |
45 | 23 | sudo apt-get update |
46 | | - sudo apt-get install -y gcc make build-essential |
47 | | -
|
48 | | - - name: Build Linux binary |
49 | | - run: | |
50 | | - ./configure |
51 | | - make clean |
52 | | - make |
53 | | - # Rename the built executable for clarity |
54 | | - mv tcc tcc-linux |
55 | | -
|
56 | | - - name: Upload Linux binary artifact |
57 | | - uses: actions/upload-artifact@v4 |
58 | | - with: |
59 | | - name: tcc-linux |
60 | | - path: tcc-linux |
61 | | - |
62 | | - # ----------------------------------------------------------- |
63 | | - # 3. Cross-compile the Windows binary using mingw on Ubuntu. |
64 | | - # ----------------------------------------------------------- |
65 | | - build-windows: |
66 | | - needs: git-sync |
67 | | - runs-on: ubuntu-latest |
68 | | - steps: |
69 | | - - name: Checkout mirror repository |
70 | | - uses: actions/checkout@v4 |
71 | | - with: |
72 | | - repository: Tiny-C-Compiler/mirror-repository |
73 | | - ref: mob |
74 | | - ssh-key: ${{ secrets.SSH_PRIVATE_KEY }} |
75 | | - fetch-depth: 0 |
| 24 | + sudo apt-get install -y build-essential |
76 | 25 |
|
77 | | - - name: Install Windows cross-compilation dependencies |
| 26 | + - name: Setup Windows build tools |
| 27 | + if: matrix.os == 'windows-latest' |
78 | 28 | run: | |
79 | | - sudo apt-get update |
80 | | - sudo apt-get install -y \ |
81 | | - gcc-mingw-w64-x86-64 \ |
82 | | - binutils-mingw-w64-x86-64 \ |
83 | | - mingw-w64-x86-64-dev \ |
84 | | - make build-essential |
| 29 | + choco install mingw -y |
| 30 | + shell: powershell |
85 | 31 |
|
86 | | - - name: Prepare Windows build environment |
| 32 | + # --- Run your build script (adjust commands as needed) |
| 33 | + - name: Build TinyCC |
87 | 34 | run: | |
88 | | - # Clean previous build artifacts (except the Linux host binary) |
89 | | - make clean |
90 | | - rm -f config.mak config.h |
91 | | - # Configure for Windows cross-compilation using mingw |
92 | | - ./configure \ |
93 | | - --cross-prefix=x86_64-w64-mingw32- \ |
94 | | - --cpu=x86_64 \ |
95 | | - --extra-cflags="-static" \ |
96 | | - --extra-ldflags="-static" |
97 | | - # Adjust the Makefile: |
98 | | - # Use the already built Linux executable as a helper if needed. |
99 | | - sed -i 's/^\(HOST_CC\s*=\s*\).*/\1.\/tcc-linux/' Makefile |
100 | | - sed -i 's/^\(CC\s*=\s*\).*/\1x86_64-w64-mingw32-gcc/' Makefile |
101 | | - sed -i 's/\(CFLAGS\s*+=\)/\1 -DWIN32/' Makefile |
| 35 | + if [ "$(uname -s)" = "Linux" ]; then |
| 36 | + # For Linux, assume you have a Makefile |
| 37 | + make clean && make |
| 38 | + else |
| 39 | + # For Windows, run your batch file |
| 40 | + ./build-tcc.bat |
| 41 | + fi |
| 42 | + shell: bash |
102 | 43 |
|
103 | | - - name: Build Windows binary |
| 44 | + # --- Collect artifacts (adjust paths to your outputs) |
| 45 | + - name: Prepare artifact folder |
104 | 46 | run: | |
105 | | - # First build helper libraries with the host compiler |
106 | | - make libtcc1.a |
107 | | - # Then build the Windows executable |
108 | | - make tcc |
109 | | - mv tcc tcc-windows.exe |
| 47 | + mkdir artifact |
| 48 | + # For example, copy the built binaries or ZIP files: |
| 49 | + cp tcc.exe artifact/ 2>/dev/null || true |
| 50 | + cp libtcc.dll artifact/ 2>/dev/null || true |
| 51 | + cp -r some_output_folder artifact/ 2>/dev/null || true |
110 | 52 |
|
111 | | - - name: Upload Windows binary artifact |
112 | | - uses: actions/upload-artifact@v4 |
| 53 | + - name: Upload artifact |
| 54 | + uses: actions/upload-artifact@v3 |
113 | 55 | with: |
114 | | - name: tcc-windows |
115 | | - path: tcc-windows.exe |
| 56 | + name: build-${{ matrix.os }} |
| 57 | + path: artifact/ |
116 | 58 |
|
117 | | - # ----------------------------------------------------------- |
118 | | - # 4. Create or update the “latest” GitHub Release on the mirror repo. |
119 | | - # ----------------------------------------------------------- |
120 | | - create-release: |
121 | | - needs: [build-linux, build-windows] |
| 59 | + release: |
| 60 | + needs: build |
122 | 61 | runs-on: ubuntu-latest |
123 | 62 | steps: |
124 | 63 | - name: Download Linux artifact |
125 | | - uses: actions/download-artifact@v4 |
| 64 | + uses: actions/download-artifact@v3 |
126 | 65 | with: |
127 | | - name: tcc-linux |
| 66 | + name: build-ubuntu-latest |
128 | 67 |
|
129 | 68 | - name: Download Windows artifact |
130 | | - uses: actions/download-artifact@v4 |
| 69 | + uses: actions/download-artifact@v3 |
131 | 70 | with: |
132 | | - name: tcc-windows |
| 71 | + name: build-windows-latest |
133 | 72 |
|
134 | | - - name: Create GitHub Release |
135 | | - uses: softprops/action-gh-release@v1 |
| 73 | + # --- Combine both artifacts into one release folder and zip them |
| 74 | + - name: Prepare release package |
| 75 | + run: | |
| 76 | + mkdir release |
| 77 | + cp -r build-ubuntu-latest/* release/ || true |
| 78 | + cp -r build-windows-latest/* release/ || true |
| 79 | + cd release |
| 80 | + zip -r ../latest-release.zip . |
| 81 | + |
| 82 | + # --- Clone the mirror repository (branch "mob") using a dedicated token |
| 83 | + - name: Checkout mirror repository |
| 84 | + uses: actions/checkout@v3 |
136 | 85 | with: |
137 | 86 | repository: Tiny-C-Compiler/mirror-repository |
| 87 | + ref: mob |
138 | 88 | token: ${{ secrets.MIRROR_REPO_TOKEN }} |
139 | | - tag_name: latest |
140 | | - overwrite: true |
141 | | - files: | |
142 | | - tcc-linux |
143 | | - tcc-windows.exe |
144 | | - body: | |
145 | | - Automated cross-platform build containing: |
146 | | - - Linux executable (ELF64) |
147 | | - - Windows executable (PE32+) |
148 | | - Built from mob branch at $(date -u +"%Y-%m-%dT%H:%M:%SZ") |
| 89 | + path: mirror |
| 90 | + |
| 91 | + # --- Copy the release package into the mirror repository and push changes |
| 92 | + - name: Update mirror repository with new release |
| 93 | + run: | |
| 94 | + cp latest-release.zip mirror/ |
| 95 | + cd mirror |
| 96 | + git config user.name "github-actions[bot]" |
| 97 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 98 | + git add latest-release.zip |
| 99 | + git commit -m "Update latest release" || echo "No changes to commit" |
| 100 | + git push origin mob |
| 101 | +
|
| 102 | + # --- Create or update a GitHub Release on the mirror repository using gh CLI |
| 103 | + - name: Create GitHub Release in mirror repository |
| 104 | + run: | |
| 105 | + gh release create latest latest-release.zip \ |
| 106 | + --repo Tiny-C-Compiler/mirror-repository \ |
| 107 | + --title "Latest Release" \ |
| 108 | + --notes "Automated build and release on $(date -u)" |
| 109 | + env: |
| 110 | + GITHUB_TOKEN: ${{ secrets.MIRROR_REPO_TOKEN }} |
0 commit comments