Github Action Workflow Warning: Context access might be invalid

Update

想了一下 虽然没有错误,但其实设置环境 变量不是很好的习惯, 这种可以分成两个job 

第一个job 先判断是否有相应变化,之后用outputs 传送给下一个 job  修改了 

这个报警 还是有道理的 如果系统环境发生什么故障,设置环境变量失败,后续可能会有bug。 

------ 

name: Auto Branch Creation

on:
  issues:
    types:
      - opened
      - edited

permissions:
  contents: write

jobs:
  create-branch:
    runs-on: ubuntu-latest
    steps:
      - name: Check if branch needs to be created and determine type
        id: check-branch
        run: |
          ISSUE_TITLE="${{ github.event.issue.title }}"
          echo "Issue Title: $ISSUE_TITLE"

          # Check if the title contains FEATURE or BUG
          if echo "$ISSUE_TITLE" | grep -iq "FEATURE"; then
            echo "Branch type: feature"
            echo "branch_type=feature" >> $GITHUB_ENV
            echo "create_branch=true" >> $GITHUB_ENV
          elif echo "$ISSUE_TITLE" | grep -iq "BUG"; then
            echo "Branch type: bug"
            echo "branch_type=bug" >> $GITHUB_ENV
            echo "create_branch=true" >> $GITHUB_ENV
          else
            echo "Branch creation not required."
            echo "create_branch=false" >> $GITHUB_ENV
          fi

      - name: Exit if branch creation is not required
        if: env.create_branch == 'false'
        run: echo "No branch will be created for this issue."

      - name: Check out the repository
        if: env.create_branch == 'true'
        uses: actions/checkout@v2

      - name: Set up Git
        if: env.create_branch == 'true'
        run: |
          git config --global user.name 'github-actions[bot]'
          git config --global user.email 'github-actions[bot]@users.noreply.github.com'

      - name: Create branch based on type
        if: env.create_branch == 'true'
        env:
          ISSUE_NUMBER: ${{ github.event.issue.number }}
          BRANCH_TYPE: ${{ env.branch_type }}
        run: |
          # Generate the branch name
          BRANCH_NAME="${BRANCH_TYPE}/issue-${ISSUE_NUMBER}"
          echo "Creating branch: $BRANCH_NAME"

          # Create and push the branch
          git checkout -b "$BRANCH_NAME"
          git push "https://${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" "$BRANCH_NAME"

对于使用环境变量来 进行自定义的 情况下, 虽然这样并没有错误但是目前 extension 没有办法判断是否是有问题所以会报出warning。  目前官方已经认可是 extension的问题, 将来可能会屏蔽相关告警的办法, 目前的warning 无视即可。

https://github.com/github/vscode-github-actions/issues/47

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值