Trying to pass variables between steps using outputs

This commit is contained in:
hitanshu310 2025-06-10 21:21:39 +05:30
parent 1980b49272
commit cd4b2ae2d8
2 changed files with 18 additions and 38 deletions

View File

@ -6,8 +6,6 @@ on:
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
container:
image: catthehacker/ubuntu:act-latest
steps: steps:
- name: Check out repository code - name: Check out repository code
uses: actions/checkout@v4 uses: actions/checkout@v4
@ -18,22 +16,5 @@ jobs:
java-version: '17' java-version: '17'
- name: Validate Gradle Wrapper - name: Validate Gradle Wrapper
uses: gradle/actions/wrapper-validation@v3 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 - name: Gradle build
run: ./gradlew build --info run: ./gradlew build --info

View File

@ -18,29 +18,28 @@ jobs:
with: with:
distribution: 'zulu' distribution: 'zulu'
java-version: '17' java-version: '17'
- name: Validate Gradle Wrapper
uses: gradle/actions/wrapper-validation@v3
- name: Get latest tag - name: Get latest tag
id: get_tag id: get_tag
run: | run: |
export "VERSION=$(git describe --tags --abbrev=0)" >> $GITEA_ENV VERSION=$(git describe --tags --abbrev=0)
echo "${VERSION}" echo "VERSION=${VERSION}" >> $GITEA_OUTPUT
export "MAJOR=$(echo ${VERSION} | /usr/bin/cut -d "." -f 1)" >> $GITEA_ENV MAJOR=$(echo ${VERSION} | cut -d "." -f 1)
echo "MAJOR=${MAJOR}" echo "MAJOR=${MAJOR}" >> $GITEA_OUTPUT
export "MINOR=$(echo ${VERSION} | cut -d "." -f 2)" >> $GITEA_ENV MINOR=$(echo ${VERSION} | cut -d "." -f 2)
echo "MINOR=${MINOR}" echo "MINOR=${MINOR}" >> $GITEA_OUTPUT
export "PATCH=$(echo ${VERSION} | cut -d "." -f 3)" >> $GITEA_ENV PATCH=$(echo ${VERSION} | cut -d "." -f 3)
echo "PATCH=${PATCH}" echo "PATCH=${PATCH}" >> $GITEA_OUTPUT
- name: Increment version - name: Increment version
id: calc_new_tag
run: | run: |
. $GITEA_ENV echo "NEW_PATCH=$((${{ steps.get_id.outputs.PATCH }} + 1))" >> $GITEA_OUTPUT
export "PATCH=$((${PATCH} + 1))" >> $GITEA_ENV echo "NEW_VERSION=$( ${{ steps.get_id.outputs.MAJOR }}.${{ steps.get_id.outputs.MINOR }}.${{ steps.get_id.outputs.NEW_PATCH }})" >> $GITEA_OUTPUT
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)"
- name: Create and push tag - name: Create and push tag
run: | run: |
git tag -a ${NEW_VERSION} -m "${COMMIT_MESSAGE}" git tag -a ${{ steps.calc_new_tag.outputs.NEW_VERSION }} -m "Pushing new version ${{ steps.calc_new_tag.outputs.NEW_VERSION }}"
git push origin ${NEW_VERSION} git push origin ${{ steps.calc_new_tag.outputs.NEW_VERSION }}
- name: Log in to Gitea Docker Registry - name: Log in to Gitea Docker Registry
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
@ -48,10 +47,10 @@ jobs:
username: hitanshu username: hitanshu
password: ${{ secrets.TOKEN }} password: ${{ secrets.TOKEN }}
- name: Gradle build - 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 - 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 - name: Push to Gitea Registry
run: | run: |
docker push 192.168.0.100:8928/hithomelabs/cftunnels:test 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 }}