From fa59a730ca2367bb88e8c1f52aad5255f9db6747 Mon Sep 17 00:00:00 2001 From: ivvist Date: Sun, 26 May 2024 12:11:04 +0200 Subject: [PATCH] fix workflow - wrong check team members --- .github/workflows/rc.yml | 15 ++++++ .github/workflows/rc1.yml | 98 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 .github/workflows/rc1.yml diff --git a/.github/workflows/rc.yml b/.github/workflows/rc.yml index f1e78eb..78fa30b 100644 --- a/.github/workflows/rc.yml +++ b/.github/workflows/rc.yml @@ -21,3 +21,18 @@ jobs: secrets: git_token: ${{ secrets.REPOREADING_TOKEN }} + handle-failure: + needs: make-rc + runs-on: ubuntu-latest + if: failure() + steps: + - name: Add comment to issue + env: + GH_TOKEN: ${{ secrets.REPOREADING_TOKEN }} + org: 'IVVORG' + repo: 'public-test-repo' + user: '${{ github.event.issue.user.login }}' + issue: '${{ github.event.issue.number }}' + body: "Error occured" + run: | + curl -s https://raw.githubusercontent.com/untillpro/ci-action/master/scripts/add-issue-commit.sh | bash diff --git a/.github/workflows/rc1.yml b/.github/workflows/rc1.yml new file mode 100644 index 0000000..3f6883d --- /dev/null +++ b/.github/workflows/rc1.yml @@ -0,0 +1,98 @@ +name: Make release candidate + +on: + workflow_call: + inputs: + org: + required: true + type: string + repo: + required: true + type: string + team: + required: true + type: string + user: + required: true + type: string + issue: + required: true + type: string + secrets: + git_token: + required: true + +jobs: + make_rc: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: main # Checkout the main branch + + - name: Add comment to issue + env: + GH_TOKEN: ${{ secrets.git_token }} + org: ${{ inputs.org }} + repo: ${{ inputs.repo }} + issue: ${{ inputs.issue }} + body: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + run: | + curl -s https://raw.githubusercontent.com/untillpro/ci-action/master/scripts/add-issue-commit.sh | bash + + - name: Check Issue + run: | + echo "org: ${{ inputs.org }}" + echo "team: ${{ inputs.team }}" + echo "user: ${{ inputs.user }}" + echo "title: ${{ inputs.issue-title }}" + + ORG_NAME=${{ inputs.org }} + TEAM_NAME=${{ inputs.team }} + USER_NAME=${{ inputs.user }} + + echo "org1: $ORG_NAME" + echo "team1: $TEAM_NAME" + echo "user1: $USER_NAME" + # Check organization membership + ORG_MEMBERSHIP=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: Bearer ${{ secrets.git_token }}" "https://api.github.com/orgs/$ORG_NAME/members/$USER_NAME") + + if [[ $ORG_MEMBERSHIP -ne 404 ]]; then + echo "The user $USER_NAME is a member of the organization $ORG_NAME." + else + echo "The user $USER_NAME is not a member of the organization $ORG_NAME." + exit 1 + fi + + # Check team membership + TEAM_MEMBERSHIP=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: Bearer ${{ secrets.git_token }}" "https://api.github.com/orgs/$ORG_NAME/teams/$TEAM_NAME/memberships/$USER_NAME") + echo "$TEAM_MEMBERSHIP" + if [[ $TEAM_MEMBERSHIP -eq 200 ]]; then + echo "The user $USER_NAME is a member of the team $TEAM_NAME within the organization $ORG_NAME." + else + echo "The user $USER_NAME is not a member of the team $TEAM_NAME within the organization $ORG_NAME." + exit 1 + fi + +# Make RC for the repo here: + + - name: Re-create release branch + env: + GH_TOKEN: ${{ secrets.git_token }} + org: ${{ inputs.org }} + repo: ${{ inputs.repo }} + run: | + git config --local user.email "v.istratenko@dev.untill.com" + git config --local user.name "upload-robot" + git config --global url.https://${{ secrets.git_token }}@github.com/.insteadOf https://github.com/ + curl -s https://raw.githubusercontent.com/untillpro/ci-action/master/scripts/rc.sh | bash + + - name: Close issue + env: + GH_TOKEN: ${{ secrets.git_token }} + org: ${{ inputs.org }} + repo: ${{ inputs.repo }} + issue: ${{ inputs.issue }} + run: curl -s https://raw.githubusercontent.com/untillpro/ci-action/master/scripts/close-issue.sh | bash