GitHub Workflow中set-output警告更新后仍未消除的问题排查
GitHub Workflow set-output语法更新后警告未消除的解决方法
问题描述
尝试更新GitHub Workflow中的set-output语法,已参考GitHub官方指南修改,但仍收到语法过时警告。当前使用actions/checkout@v3,相关工作流代码如下(原代码仅注释了新语法,未实际启用):
jobs: build: runs-on: ubuntu-latest outputs: branch: ${{ steps.extract_branch.outputs.branch }} channel: ${{ steps.extract_channel.outputs.channel }} steps: - uses: actions/checkout@v3 # In this step, this action saves a list of existing images, # the cache is created without them in the post run. # It also restores the cache if it exists. - name: Install Octopus CLI 🐙 uses: OctopusDeploy/install-octopus-cli-action@v3 - name: Extract branch name shell: bash id: extract_branch run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" # run: echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT - name: Determine Octopus Deployment Channel shell: bash id: extract_channel run: | BRANCH="${{ steps.extract_branch.outputs.branch }}" CHANNEL="Features" if [[ "$BRANCH" == "main" ]] || [[ "$BRANCH" == "release/*" ]]; then CHANNEL="default" fi echo "##[set-output name=channel;]$(echo $CHANNEL)" # echo "channel=$(echo $CHANNEL)" >> $GITHUB_OUTPUT
解决步骤
- 彻底移除旧的
##[set-output]语法,启用注释中的echo "key=value" >> $GITHUB_OUTPUT格式 - 简化变量输出逻辑:无需嵌套
echo命令,直接输出变量即可,减少冗余 - 修正分支匹配逻辑:bash中
==不支持通配符,需用=~结合正则表达式匹配release/*分支
修改后的完整工作流代码
jobs: build: runs-on: ubuntu-latest outputs: branch: ${{ steps.extract_branch.outputs.branch }} channel: ${{ steps.extract_channel.outputs.channel }} steps: - uses: actions/checkout@v3 # In this step, this action saves a list of existing images, # the cache is created without them in the post run. # It also restores the cache if it exists. - name: Install Octopus CLI 🐙 uses: OctopusDeploy/install-octopus-cli-action@v3 - name: Extract branch name shell: bash id: extract_branch # 简化分支提取逻辑,直接输出到GITHUB_OUTPUT run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT - name: Determine Octopus Deployment Channel shell: bash id: extract_channel run: | BRANCH="${{ steps.extract_branch.outputs.branch }}" CHANNEL="Features" # 使用正则匹配所有以release/开头的分支 if [[ "$BRANCH" == "main" ]] || [[ "$BRANCH" =~ ^release/ ]]; then CHANNEL="default" fi # 直接输出CHANNEL变量到GITHUB_OUTPUT echo "channel=$CHANNEL" >> $GITHUB_OUTPUT
关键说明
- 旧的
##[set-output]命令已被GitHub标记为过时,必须完全替换为$GITHUB_OUTPUT的输出方式 - bash环境中,
==仅支持精确字符串匹配,通配符匹配需使用=~运算符结合正则表达式 - 避免使用
echo $(echo $VAR)的冗余写法,直接引用变量即可减少不必要的系统调用
内容的提问来源于stack exchange,提问作者Sabrina Grosse
相关产品推荐
相关产品推荐

