From cd4b2ae2d86de6dac2635941d374cea641252b11 Mon Sep 17 00:00:00 2001 From: hitanshu310 Date: Tue, 10 Jun 2025 21:21:39 +0530 Subject: [PATCH] Trying to pass variables between steps using outputs --- .gitea/workflows/test_build.yml | 19 ----------- .gitea/workflows/test_image_build_push.yml | 37 +++++++++++----------- 2 files changed, 18 insertions(+), 38 deletions(-) diff --git a/.gitea/workflows/test_build.yml b/.gitea/workflows/test_build.yml index 3817663..ae070cd 100644 --- a/.gitea/workflows/test_build.yml +++ b/.gitea/workflows/test_build.yml @@ -6,8 +6,6 @@ on: jobs: build: runs-on: ubuntu-latest - container: - image: catthehacker/ubuntu:act-latest steps: - name: Check out repository code uses: actions/checkout@v4 @@ -18,22 +16,5 @@ jobs: java-version: '17' - name: Validate Gradle Wrapper uses: gradle/actions/wrapper-validation@v3 - - name: Get latest tag - id: get_tag - run: | - export "VERSION=$(git describe --tags --abbrev=0)" >> $GITEA_ENV - echo "${VERSION}" - export "MAJOR=$(echo ${VERSION} | /usr/bin/cut -d "." -f 1)" >> $GITEA_ENV - echo "MAJOR=${MAJOR}" - export "MINOR=$(echo ${VERSION} | cut -d "." -f 2)" >> $GITEA_ENV - echo "MINOR=${MINOR}" - export "PATCH=$(echo ${VERSION} | cut -d "." -f 3)" >> $GITEA_ENV - echo "PATCH=${PATCH}" - - name: Increment version - run: | - . $GITEA_ENV - export "PATCH=$((${PATCH} + 1))" >> $GITEA_ENV - export "NEW_VERSION=$(echo ${MAJOR}.${MINOR}.${PATCH})" >> $GITEA_ENV - echo "NEW_VERSION=${NEW_VERSION}" - name: Gradle build run: ./gradlew build --info \ No newline at end of file diff --git a/.gitea/workflows/test_image_build_push.yml b/.gitea/workflows/test_image_build_push.yml index d96fd01..425a819 100644 --- a/.gitea/workflows/test_image_build_push.yml +++ b/.gitea/workflows/test_image_build_push.yml @@ -18,29 +18,28 @@ jobs: with: distribution: 'zulu' java-version: '17' + - name: Validate Gradle Wrapper + uses: gradle/actions/wrapper-validation@v3 - name: Get latest tag id: get_tag run: | - export "VERSION=$(git describe --tags --abbrev=0)" >> $GITEA_ENV - echo "${VERSION}" - export "MAJOR=$(echo ${VERSION} | /usr/bin/cut -d "." -f 1)" >> $GITEA_ENV - echo "MAJOR=${MAJOR}" - export "MINOR=$(echo ${VERSION} | cut -d "." -f 2)" >> $GITEA_ENV - echo "MINOR=${MINOR}" - export "PATCH=$(echo ${VERSION} | cut -d "." -f 3)" >> $GITEA_ENV - echo "PATCH=${PATCH}" + VERSION=$(git describe --tags --abbrev=0) + echo "VERSION=${VERSION}" >> $GITEA_OUTPUT + MAJOR=$(echo ${VERSION} | cut -d "." -f 1) + echo "MAJOR=${MAJOR}" >> $GITEA_OUTPUT + MINOR=$(echo ${VERSION} | cut -d "." -f 2) + echo "MINOR=${MINOR}" >> $GITEA_OUTPUT + PATCH=$(echo ${VERSION} | cut -d "." -f 3) + echo "PATCH=${PATCH}" >> $GITEA_OUTPUT - name: Increment version + id: calc_new_tag run: | - . $GITEA_ENV - export "PATCH=$((${PATCH} + 1))" >> $GITEA_ENV - export "NEW_VERSION=$(echo ${MAJOR}.${MINOR}.${PATCH})" >> $GITEA_ENV - echo "NEW_VERSION=${NEW_VERSION}" - - name: Extract commit message - run: echo "COMMIT_MESSAGE=$(git log -1 --pretty=%B)" + echo "NEW_PATCH=$((${{ steps.get_id.outputs.PATCH }} + 1))" >> $GITEA_OUTPUT + echo "NEW_VERSION=$( ${{ steps.get_id.outputs.MAJOR }}.${{ steps.get_id.outputs.MINOR }}.${{ steps.get_id.outputs.NEW_PATCH }})" >> $GITEA_OUTPUT - name: Create and push tag run: | - git tag -a ${NEW_VERSION} -m "${COMMIT_MESSAGE}" - git push origin ${NEW_VERSION} + git tag -a ${{ steps.calc_new_tag.outputs.NEW_VERSION }} -m "Pushing new version ${{ steps.calc_new_tag.outputs.NEW_VERSION }}" + git push origin ${{ steps.calc_new_tag.outputs.NEW_VERSION }} - name: Log in to Gitea Docker Registry uses: docker/login-action@v3 with: @@ -48,10 +47,10 @@ jobs: username: hitanshu password: ${{ secrets.TOKEN }} - name: Gradle build - run: ./gradlew bootBuildImage --imageName=192.168.0.100:8928/hithomelabs/cftunnels:${NEW_VERSION} + run: ./gradlew bootBuildImage --imageName=192.168.0.100:8928/hithomelabs/cftunnels:${{ steps.calc_new_tag.outputs.NEW_VERSION }} - name: Tag image as test - run: docker tag 192.168.0.100:8928/hithomelabs/cftunnels:${NEW_VERSION} 192.168.0.100:8928/hithomelabs/cftunnels:test + run: docker tag 192.168.0.100:8928/hithomelabs/cftunnels:${{ steps.calc_new_tag.outputs.NEW_VERSION }} 192.168.0.100:8928/hithomelabs/cftunnels:test - name: Push to Gitea Registry run: | docker push 192.168.0.100:8928/hithomelabs/cftunnels:test - docker push 192.168.0.100:8928/hithomelabs/cftunnels:${NEW_VERSION} + docker push 192.168.0.100:8928/hithomelabs/cftunnels:${{ steps.calc_new_tag.outputs.NEW_VERSION }}