如何在github actions中设置中文支持

问题描述 投票:0回答:1

我使用vs2022构建c++项目
我用 printf 写中文字符串。
我发现中文都是乱码。像这样:

enter image description here

enter image description here

我的构建脚本

name: C++ Build with Dependencies

#on: [push] 
on:
  workflow_dispatch: 
  
permissions:
  contents: write
  
jobs:
  build:
    strategy:
      matrix:
        configuration: [Release]
        platform: [x86]

    runs-on: windows-latest 

    steps:
      - name: Checkout main repository code
        uses: actions/checkout@v4

      - name: Setup Console Code Page to GBK
        run: chcp 936
        shell: pwsh
        
      - name: Checkout dependency repository (xengine)
        uses: actions/checkout@v3
        with:
          repository: libxengine/xengine
          path: xengine

      - name: Set up Dependency Environment Variables
        run: |
          echo "XENGINE_INCLUDE=${{ github.workspace }}/xengine" | Out-File -FilePath $env:GITHUB_ENV -Append
          echo "XENGINE_LIB32=${{ github.workspace }}/xengine/XEngine_Windows/x86" | Out-File -FilePath $env:GITHUB_ENV -Append
          echo "XENGINE_LIB64=${{ github.workspace }}/xengine/XEngine_Windows/x64" | Out-File -FilePath $env:GITHUB_ENV -Append
        shell: pwsh
        
      - name: Setup MSBuild
        uses: microsoft/[email protected]
      #编译
      - name: Build Solution
        run: msbuild XEngine_Source/XEngine_StorageApp.sln /p:Configuration=${{ matrix.configuration }} /p:Platform=${{ matrix.platform }}

      - name: Copy Build binaries for x86
        run: |
          mkdir -p "x86/XEngine_StorageApp"
          cp -r ./XEngine_Release/* x86/XEngine_StorageApp/
          cp -r ./XEngine_Source/Release/*.dll x86/XEngine_StorageApp/
          cp -r ./XEngine_Source/Release/*.exe x86/XEngine_StorageApp/
          cp -r ./XEngine_Source/VSCopy_x86.bat x86/XEngine_StorageApp/
          cd x86/XEngine_StorageApp && ./VSCopy_x86.bat
          cd ..
          cd ..
          7z a XEngine_StorageApp-x86-Windows.zip ./x86/XEngine_StorageApp
        shell: pwsh

      - name: Calculate new tag
        id: newtag
        shell: bash
        run: |
          git fetch --tags
          TAG=$(git tag --sort=-v:refname | head -n 1)
          MAJOR=$(echo $TAG | cut -d '.' -f 1)
          MINOR=$(echo $TAG | cut -d '.' -f 2)
          PATCH=$(echo $TAG | cut -d '.' -f 3)
          BUILD=$(echo $TAG | cut -d '.' -f 4)
          MINOR_BUMP=$((MINOR + 1))
          NEW_TAG="${MAJOR}.${MINOR_BUMP}.0.${BUILD}"
          echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV
          git config --local user.email "[email protected]"
          git config --local user.name "GitHub Action"
          git tag $NEW_TAG
          git push origin $NEW_TAG
    
      - name: Create Release
        id: create_release
        uses: softprops/action-gh-release@v1
        with:
          tag_name: ${{ env.NEW_TAG }}
          name: Release ${{ env.NEW_TAG }}
          body: |
            [${{ github.sha }}](https://github.com/xengine-qyt/XEngine_Storage/commit/${{ github.sha }})
            ${{ github.event.head_commit.message }}
          draft: false
          prerelease: false
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
     
      - name: Upload x86 Release Asset
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ steps.create_release.outputs.upload_url }}
          asset_path: ./XEngine_StorageApp-x86-Windows.zip
          asset_name: XEngine_StorageApp-x86-Windows.zip
          asset_content_type: application/zip

在我自己的中文系统环境下,输出正常。当我尝试编码输出 UNICODE 字符串时,它不起作用。我该怎么做才能输出中文?

c++ github-actions
1个回答
0
投票

这些步骤将在独立的 shell 环境中运行。

chcp 936
不会影响后续步骤。您需要将其添加到使用 GBK 字符的特定步骤中。

© www.soinside.com 2019 - 2024. All rights reserved.