Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Committing and pushing a workflow within the runner is not triggering a new workflow on another branch. #32615

Open
renatohberg opened this issue Nov 22, 2024 · 8 comments
Labels
topic/gitea-actions related to the actions of Gitea type/bug

Comments

@renatohberg
Copy link

Description

I have a release process in which the code merged via pull request to the "develop" or "hotfix" branch will perform all the testing and build steps, and if everything goes well, it will create a new branch of the "release/" type with the correct version in some files.
Up to this point, my workflow is working correctly, but when I push the new "release/
" branch, it is being created but is not starting the workflow automatically.

Gitea Version

1.22.3

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

Debian 12

How are you running Gitea?

I'm running Gitea on my Virtual Machine with Debian 12, and the Runners on Docker.

Database

PostgreSQL

@lunny
Copy link
Member

lunny commented Nov 22, 2024

How did you push the branch? You need another token to do that. Action user cannot trigger a new workflow which is by design to avoid recycle triggering.

@kemzeb kemzeb added the topic/gitea-actions related to the actions of Gitea label Nov 23, 2024
@renatohberg
Copy link
Author

renatohberg commented Nov 23, 2024

After you commented on the user, I made some changes to see if it would solve the problem. Here are the changes I made in the Gitea action

  1. I changed the email and name of the user before the commit.

git config --global user.name "myotheruser"
git config --global user.email "[email protected]"

  1. I created the new release branch

git checkout -b release/1.25.0

  1. I committed the changes

git commit -m "Automatic Release Commit"

  1. I changed the remote URL of the repository, to force the push with another user.

git remote set-url origin http://myotheruser:[email protected]/myfirstuser/java-spring-template.git

  1. I pushed

git push --set-upstream origin

Even forcing the push with another user, the workflow is not being started on the new branch.

@renatohberg
Copy link
Author

image

@lunny
Copy link
Member

lunny commented Nov 23, 2024

Can you also post your workflow in the default branch?

@renatohberg
Copy link
Author

renatohberg commented Nov 23, 2024

Sure.

name: "Java Pipeline"

on:
  create:
    branches:
      - '*'
  push:
    branches:
      - '*'

jobs:
  build:
    runs-on: ubuntu-latest
    
    steps:
      - name: "Repository checkout"
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: "Extract Java version"
        run: |
          echo "JAVA_VERSION=21" >> $GITEA_ENV

      - name: "Set up JDK"
        uses: actions/setup-java@v4
        with:
          java-version: '${{ env.JAVA_VERSION }}'
          distribution: 'temurin'

      - name: Run Load Change Version
        if: github.ref_name != 'main'
        uses: http://${{ vars.OWNER_USERNAME }}:${{ secrets.OWNER_TOKEN }}@gitea.myDomain.com/MyDomain-Actions/load-change-version-action@main
        with:
          user: "${{ vars.OWNER_USERNAME }}"
          token: "${{ secrets.OWNER_TOKEN }}"
          repository: "${{ github.event.repository.name }}"
          branch: "${{ github.ref_name }}"
          language: "java"

      - name: "Run unit tests"
        run: |
          chmod +x ./gradlew
          ./gradlew test

      # - name: "Dependency check"
        # env:
          # NVD_API_KEY: ${{ secrets.NVD_API_KEY }}
        # run: |
          # ./gradlew dependencyCheckAnalyze


      - name: "Sonarqube scan"
        uses: http://${{ vars.OWNER_USERNAME }}:${{ secrets.OWNER_TOKEN }}@gitea.myDomain.com/MyDomain-Actions/sonar-action@main
        with:
          engine: "gradle"
          token: ${{ secrets.SONAR_TOKEN }}

      - name: "Zap scan"
        run: |
          echo "Executando ação para qualquer branch!"

      - name: "Build"
        run: "./gradlew build"


      - name: Run Release
        if: github.ref_name == 'develop' || github.ref_name == 'hotfix' || startsWith(github.ref_name, 'release/')
        uses: http://${{ vars.OWNER_USERNAME }}:${{ secrets.OWNER_TOKEN }}@gitea.myDomain.com/MyDomain-Actions/release-action@main
        with:
          user: "${{ vars.OWNER_USERNAME }}"
          email: "${{ vars.OWNER_EMAIL }}"
          token: "${{ secrets.OWNER_TOKEN }}"
          repository-owner: "MyDomain"
          repository: "${{ github.event.repository.name }}"
          branch: "${{ github.ref_name }}"
          current-version: "${{ env.CURRENT_VERSION }}"
          new-version: "${{ env.NEW_VERSION }}"

      - name: "Publish Maven Image"
        if: github.ref_name != 'main' && github.ref_name != 'develop' && github.ref_name != 'hotfix'
        run: |
          echo "Executando ação para qualquer branch!"

      - name: "Build Docker Image"
        if: github.ref_name != 'main' && github.ref_name != 'develop' && github.ref_name != 'hotfix'
        run: |
          echo "Executando ação para qualquer branch!"

      - name: "Publish Docker Image"
        if: github.ref_name != 'main' && github.ref_name != 'develop' && github.ref_name != 'hotfix'
        run: |
          echo "Executando ação para qualquer branch!"

  deploy:
    needs: build
    runs-on: ubuntu-latest
    
    steps:
      - name: "Deploy image"
        run: |
          echo "Type: k8s"
          echo "Image: ---"

@renatohberg
Copy link
Author

The "Run Release" task is a composite action that basically executes the script below.

#!/bin/bash

WORKSPACE_PATH="/workspace/MyDomain/release-action"

source ${WORKSPACE_PATH}/integrations/utils/logging.sh

git_config() {
    git config --global user.name "myanotheruser"
    git config --global user.email "[email protected]"
}

git_checkout_release() {
    NEW_RELEASE_BRANCH="release/${NEW_VERSION}"

    # Create a new Branch release/
    git checkout -b ${NEW_RELEASE_BRANCH}
}

git_commit_with_release_tag() {
    # Commit files
    git commit -m "Automatic Release Commit"

	# git remote set-url origin ${_GIT_SSH_ORIGIN}
	git remote set-url origin http://myanotheruser:[email protected]/MyDomain/java-spring-template.git

    # Push commit to origin
    git push --set-upstream origin ${NEW_RELEASE_BRANCH}
    # git push -u origin ${NEW_RELEASE_BRANCH}
}

main() {
    if [[ "${BRANCH}" == "develop" ]] || [[ "${BRANCH}" == "hotfix" ]]; then
        git_config "${OWNER_USERNAME}" "${OWNER_EMAIL}"

        git_checkout_release

        git_commit_with_release_tag
    else
        utils_logging_warning "Skip release generation"
    fi
}

main

@lunny
Copy link
Member

lunny commented Nov 23, 2024

composite action hasn't been supported yet.

@renatohberg
Copy link
Author

I even managed to do the process via Gitea API using the call to "Modify multiple files in a repository", but it didn't work through commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic/gitea-actions related to the actions of Gitea type/bug
Projects
None yet
Development

No branches or pull requests

3 participants