From 286f9f8803574a196b5a69c696fb80cdd045445e Mon Sep 17 00:00:00 2001 From: TechQuery Date: Thu, 2 Jan 2025 17:27:35 +0800 Subject: [PATCH 01/10] [add] Build & Test GitHub action [add] VS Code extensions [optimize] Read Me document --- .github/workflows/main.yml | 15 +++++++++++++++ .gitignore | 7 +++++-- .vscode/extensions.json | 3 +++ ReadMe.md | 28 ++++++++++++++++++---------- 4 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/main.yml create mode 100644 .vscode/extensions.json diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..3fcd04d --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,15 @@ +name: CI & CD +on: + push: + +jobs: + Build_and_Test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: xmake-io/github-action-setup-xmake@v1 + with: + xmake-version: latest + + - run: xmake && xmake run diff --git a/.gitignore b/.gitignore index d66efff..38890d1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ -# Xmake cache +# XMake cache .xmake/ build/ -# MacOS Cache +# VS Code +.vscode/settings.json + +# MacOS cache .DS_Store diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..9e0f863 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,3 @@ +{ + "recommendations": ["tboox.xmake-vscode", "ms-vscode.cpptools-extension-pack"] +} diff --git a/ReadMe.md b/ReadMe.md index 92855ab..cf6fc2a 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -2,15 +2,14 @@ The simplest C/C++ project template for beginners. +[![CI & CD](https://github.com/FreeCodeCamp-Chengdu/Cpp-quick-start/actions/workflows/main.yml/badge.svg)][1] + ## Install minimal All-in-One Development Environment ### Windows ```powershell winget install BrechtSanders.WinLibs.POSIX.MSVCRT Xmake-io.Xmake Microsoft.VisualStudioCode -# If you have building errors with XMake & MinGW, the command below might help you to fix it, -# and "somehash" in the following path is a placeholder for the actual hash of the installed package -xmake f -p mingw --mingw=%LOCALAPPDATA%\Microsoft\WinGet\Packages\BrechtSanders.WinLibs.POSIX.MSVCRT_Microsoft.Winget.Source_somehash\mingw64 -c code --install-extension tboox.xmake-vscode code --install-extension ms-vscode.cpptools-extension-pack ``` @@ -33,7 +32,7 @@ code --install-extension tboox.xmake-vscode code --install-extension ms-vscode.cpptools-extension-pack ``` -## XMake FAQ +## XMake usage > If you want to known more usage about xmake, please see https://xmake.io @@ -43,19 +42,26 @@ You can enter the project directory firstly before building project. cd projectdir ``` -1. How to build project? +### 1. How to build project? ```bash xmake ``` -2. How to configure project? +> If you have building errors with XMake & MinGW, the command below might help you to fix it, +> and "somehash" in the following path is a placeholder for the actual hash of the installed package +> +> ```powershell +> xmake f -p mingw --mingw=%LOCALAPPDATA%\Microsoft\WinGet\Packages\BrechtSanders.WinLibs.POSIX.MSVCRT_Microsoft.Winget.Source_somehash\mingw64 -c +> ``` + +### 2. How to configure project? ```bash xmake f -p [macosx|linux|iphoneos ..] -a [x86_64|i386|arm64 ..] -m [debug|release] ``` -3. Where is the build output directory? +### 3. Where is the build output directory? The default output directory is `./build` and you can configure the output directory. @@ -64,21 +70,21 @@ xmake f -o outputdir xmake ``` -4. How to run and debug target after building project? +### 4. How to run and debug target after building project? ```bash xmake run [targetname] xmake run -d [targetname] ``` -5. How to install target to the system directory or other output directory? +### 5. How to install target to the system directory or other output directory? ```bash xmake install xmake install -o installdir ``` -6. Add some frequently-used compilation flags in `xmake.lua` +### 6. Add some frequently-used compilation flags in `xmake.lua` ```lua @code @@ -112,3 +118,5 @@ xmake install -o installdir add_ldflags("-L/usr/local/lib", "-lpthread", {force = true}) @endcode ``` + +[1]: https://github.com/FreeCodeCamp-Chengdu/Cpp-quick-start/actions/workflows/main.yml From 7459a30c4b58333261f230b77d4596a4baaa17fb Mon Sep 17 00:00:00 2001 From: South Drifted Date: Thu, 2 Jan 2025 14:00:42 +0000 Subject: [PATCH 02/10] [add] GitHub release action & VS Code cloud entries --- .github/workflows/main.yml | 21 ++++++++++++++++++++- .vscode/extensions.json | 14 ++++++++++++-- ReadMe.md | 19 ++++++++++++++++++- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3fcd04d..14564ad 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,7 +4,15 @@ on: jobs: Build_and_Test: - runs-on: ubuntu-latest + strategy: + matrix: + os: + - ubuntu-latest + - macos-latest + - windows-latest + runs-on: ${{ matrix.os }} + permissions: + contents: write steps: - uses: actions/checkout@v4 @@ -13,3 +21,14 @@ jobs: xmake-version: latest - run: xmake && xmake run + + - if: startsWith(github.ref, 'refs/tags/') + uses: softprops/action-gh-release@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + prerelease: ${{ !contains(github.ref, 'refs/heads/master') }} + generate_release_notes: true + files: | + build/linux/* + build/macosx/* + build/windows/* diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 9e0f863..cc2de6f 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,3 +1,13 @@ { - "recommendations": ["tboox.xmake-vscode", "ms-vscode.cpptools-extension-pack"] -} + "recommendations": [ + "tboox.xmake-vscode", + "ms-vscode.cpptools-extension-pack", + "yzhang.markdown-all-in-one", + "redhat.vscode-yaml", + "esbenp.prettier-vscode", + "eamodio.gitlens", + "github.vscode-pull-request-github", + "github.vscode-github-actions", + "github.copilot" + ] +} \ No newline at end of file diff --git a/ReadMe.md b/ReadMe.md index cf6fc2a..cce0ba6 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -4,7 +4,21 @@ The simplest C/C++ project template for beginners. [![CI & CD](https://github.com/FreeCodeCamp-Chengdu/Cpp-quick-start/actions/workflows/main.yml/badge.svg)][1] -## Install minimal All-in-One Development Environment +[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)][2] +[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)][3] + +## Use this template project in Cloud + +1. Click the **[Use this template][4] button** on the top of this GitHub repository's home page, then create your own repository in your account/organization namespace + +2. Click the **[Open in GitHub codespaces][2] button** on the top of ReadMe file, then an **online VS Code development environment** will be started immediately + +3. Run following command in VS Code terminal to install XMake: + ```bash + curl -fsSL https://xmake.io/shget.text | bash + ``` + +## Install minimal All-in-One Development Environment in your computer ### Windows @@ -120,3 +134,6 @@ xmake install -o installdir ``` [1]: https://github.com/FreeCodeCamp-Chengdu/Cpp-quick-start/actions/workflows/main.yml +[2]: https://codespaces.new/FreeCodeCamp-Chengdu/Cpp-quick-start +[3]: https://gitpod.io/?autostart=true#https://github.com/FreeCodeCamp-Chengdu/Cpp-quick-start +[4]: https://github.com/new?template_name=Cpp-quick-start&template_owner=FreeCodeCamp-Chengdu From 672cb63e84a6a1c5c7d3e6951967005b0723e198 Mon Sep 17 00:00:00 2001 From: South Drifted Date: Thu, 2 Jan 2025 14:34:08 +0000 Subject: [PATCH 03/10] [fix] GitHub release files --- .github/workflows/main.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 14564ad..8c5afaf 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,13 +22,15 @@ jobs: - run: xmake && xmake run + - name: Find built file + shell: pwsh + run: | + echo "FILE_PATH=$(Get-ChildItem -Path build -Recurse -Filter release -File -Name)" >> $GITHUB_ENV + - if: startsWith(github.ref, 'refs/tags/') uses: softprops/action-gh-release@v2 with: token: ${{ secrets.GITHUB_TOKEN }} prerelease: ${{ !contains(github.ref, 'refs/heads/master') }} generate_release_notes: true - files: | - build/linux/* - build/macosx/* - build/windows/* + files: ${{ env.FILE_PATH }} From 859b99a359ed0f4c694f833d99b611757f6612a5 Mon Sep 17 00:00:00 2001 From: South Drifted Date: Thu, 2 Jan 2025 14:41:51 +0000 Subject: [PATCH 04/10] [fix] PowerShell filter in GitHub actions --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8c5afaf..4475704 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,7 +25,7 @@ jobs: - name: Find built file shell: pwsh run: | - echo "FILE_PATH=$(Get-ChildItem -Path build -Recurse -Filter release -File -Name)" >> $GITHUB_ENV + echo "FILE_PATH=$(Get-ChildItem -Path build -Recurse -File -Name | Where-Object { $_ -notmatch '^\.' })" >> $GITHUB_ENV - if: startsWith(github.ref, 'refs/tags/') uses: softprops/action-gh-release@v2 From f221d9494eaea1f23f29ca6584848455860f5b1a Mon Sep 17 00:00:00 2001 From: South Drifted Date: Thu, 2 Jan 2025 14:51:28 +0000 Subject: [PATCH 05/10] [fix] GitHub environment variables in PowerShell --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4475704..8c3ec7b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,7 +25,7 @@ jobs: - name: Find built file shell: pwsh run: | - echo "FILE_PATH=$(Get-ChildItem -Path build -Recurse -File -Name | Where-Object { $_ -notmatch '^\.' })" >> $GITHUB_ENV + echo "FILE_PATH=$(Get-ChildItem -Path build -Recurse -File -Name | Where-Object { $_ -notmatch '^\.' })" >> $env:GITHUB_ENV - if: startsWith(github.ref, 'refs/tags/') uses: softprops/action-gh-release@v2 From d9d0cfa8e3494f4b2235e676053fa97374a4356b Mon Sep 17 00:00:00 2001 From: South Drifted Date: Thu, 2 Jan 2025 14:54:44 +0000 Subject: [PATCH 06/10] [fix] release folder in GitHub actions --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8c3ec7b..5ebf0cf 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -33,4 +33,4 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} prerelease: ${{ !contains(github.ref, 'refs/heads/master') }} generate_release_notes: true - files: ${{ env.FILE_PATH }} + files: build/${{ env.FILE_PATH }} From 4863522ef89d7ceaa5c04dc8e5f4164021be5bfc Mon Sep 17 00:00:00 2001 From: South Drifted Date: Thu, 2 Jan 2025 15:20:00 +0000 Subject: [PATCH 07/10] [fix] Path compatibility in PowerShell --- .github/workflows/main.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5ebf0cf..fa1ab7a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,7 +8,6 @@ jobs: matrix: os: - ubuntu-latest - - macos-latest - windows-latest runs-on: ${{ matrix.os }} permissions: @@ -25,7 +24,7 @@ jobs: - name: Find built file shell: pwsh run: | - echo "FILE_PATH=$(Get-ChildItem -Path build -Recurse -File -Name | Where-Object { $_ -notmatch '^\.' })" >> $env:GITHUB_ENV + echo "FILE_PATH=$(Get-ChildItem -Path build -Recurse -File -Name | Where-Object { $_ -notmatch '^\.' } | ForEach-Object { Join-Path -Path 'build' -ChildPath $_ })" >> $env:GITHUB_ENV - if: startsWith(github.ref, 'refs/tags/') uses: softprops/action-gh-release@v2 From edaeff6cb1263e3948166dc179b475ff2365cf16 Mon Sep 17 00:00:00 2001 From: South Drifted Date: Thu, 2 Jan 2025 15:24:05 +0000 Subject: [PATCH 08/10] [fix] Path compatibility in PowerShell --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fa1ab7a..4be2483 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,7 +24,7 @@ jobs: - name: Find built file shell: pwsh run: | - echo "FILE_PATH=$(Get-ChildItem -Path build -Recurse -File -Name | Where-Object { $_ -notmatch '^\.' } | ForEach-Object { Join-Path -Path 'build' -ChildPath $_ })" >> $env:GITHUB_ENV + echo "FILE_PATH=$(Get-ChildItem -Path build -Recurse -File -Name | Where-Object { $_ -notmatch '^\.' })" >> $env:GITHUB_ENV - if: startsWith(github.ref, 'refs/tags/') uses: softprops/action-gh-release@v2 From b494a47d4f927c98622a51a52619c4ecc91fe8e6 Mon Sep 17 00:00:00 2001 From: South Drifted Date: Thu, 2 Jan 2025 15:26:34 +0000 Subject: [PATCH 09/10] [fix] Path compatibility in PowerShell --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4be2483..36528fa 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,7 +24,7 @@ jobs: - name: Find built file shell: pwsh run: | - echo "FILE_PATH=$(Get-ChildItem -Path build -Recurse -File -Name | Where-Object { $_ -notmatch '^\.' })" >> $env:GITHUB_ENV + echo "FILE_PATH=$(Get-ChildItem -Path build -Recurse -File -Name | Where-Object { $_ -notmatch '^\.' } | ForEach-Object { Join-Path -Path 'build' -ChildPath $_ })" >> $env:GITHUB_ENV - if: startsWith(github.ref, 'refs/tags/') uses: softprops/action-gh-release@v2 @@ -32,4 +32,4 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} prerelease: ${{ !contains(github.ref, 'refs/heads/master') }} generate_release_notes: true - files: build/${{ env.FILE_PATH }} + files: ${{ env.FILE_PATH }} From c4bbab018b7a859005e58e60aa4906ae79da7608 Mon Sep 17 00:00:00 2001 From: South Drifted Date: Thu, 2 Jan 2025 15:31:49 +0000 Subject: [PATCH 10/10] [fix] Path compatibility in PowerShell --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 36528fa..a282b43 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,7 +24,7 @@ jobs: - name: Find built file shell: pwsh run: | - echo "FILE_PATH=$(Get-ChildItem -Path build -Recurse -File -Name | Where-Object { $_ -notmatch '^\.' } | ForEach-Object { Join-Path -Path 'build' -ChildPath $_ })" >> $env:GITHUB_ENV + echo "FILE_PATH=$(Get-ChildItem -Path build -Recurse -File -Name | Where-Object { $_ -notmatch '^\.' } | ForEach-Object { $_ -replace '\\', '/' })" >> $env:GITHUB_ENV - if: startsWith(github.ref, 'refs/tags/') uses: softprops/action-gh-release@v2 @@ -32,4 +32,4 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} prerelease: ${{ !contains(github.ref, 'refs/heads/master') }} generate_release_notes: true - files: ${{ env.FILE_PATH }} + files: build/${{ env.FILE_PATH }}