From 1b9d93af4fdf5847db44ed5af46b80128466d9d9 Mon Sep 17 00:00:00 2001 From: Mauro Amico Date: Mon, 11 Dec 2023 16:20:03 +0100 Subject: [PATCH] set-output deprecated (#18) * set-output deprecated * typo * env * Update mx.ini * typo * Update build_development.yml * cleanup * Update build.yml * Update build.yml * Update .github/workflows/build.yml Co-authored-by: Piero Nicolli * Update build_development.yml --------- Co-authored-by: Piero Nicolli --- .github/workflows/build.yml | 44 +++++++++++-------------- .github/workflows/build_development.yml | 10 +++--- 2 files changed, 23 insertions(+), 31 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8997d4a..50b9e8e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,37 +28,31 @@ jobs: uses: docker/setup-buildx-action@v2 - name: Login to Registry - uses: docker/login-action@v1 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Get the image id - id: get_image_id run: | IMAGE_ID=$(echo ghcr.io/${{ github.repository }} | tr '[A-Z]' '[a-z]') - echo ::set-output name=IMAGE_ID::$IMAGE_ID + echo "IMAGE_ID=$IMAGE_ID" >> "$GITHUB_ENV" - - name: Extract branch name - shell: bash - run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT - id: extract_branch + - name: Get the version PR + run: echo "VERSION=${{ github.head_ref }}" >> "$GITHUB_ENV" + if: github.event_name == 'pull_request' - name: Get the version - id: get_version - run: | - VERSION="${{ steps.extract_branch.outputs.branch }}" - [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') - [ "$VERSION" == "main" ] && VERSION=latest - echo ::set-output name=VERSION::$VERSION + run: echo "VERSION=${{ github.ref_name }}" >> "$GITHUB_ENV" + if: github.event_name != 'pull_request' - name: Build and push container image uses: docker/build-push-action@v3 with: context: . push: true - tags: ${{ steps.get_image_id.outputs.IMAGE_ID }}:${{ steps.get_version.outputs.VERSION }} + tags: ${{ env.IMAGE_ID }}:${{ env.VERSION }} platforms: linux/amd64,linux/arm64 - name: Deploy to rancher # io-comune-test @@ -72,7 +66,7 @@ jobs: project-id: ${{ secrets.RANCHER_PROJECT_ID }} # organization namespace: ${{ secrets.RANCHER_NAMESPACE }} workload: ${{ secrets.RANCHER_WORKLOAD }} - image: ${{ steps.get_image_id.outputs.IMAGE_ID }}:${{ steps.get_version.outputs.VERSION }} + image: ${{ env.IMAGE_ID }}:${{ env.VERSION }} slack-hook-url: ${{ secrets.RANCHER_SLACK_HOOK_URL }} - name: Trigger job @@ -81,7 +75,7 @@ jobs: curl --fail --request POST \ --form token=${{ secrets.TOKEN }} \ --form ref=main \ - --form "variables[GITHUB_TAG]=${{ steps.get_version.outputs.VERSION }}" \ + --form "variables[GITHUB_TAG]=${{ env.VERSION }}" \ "https://gitlab.com/api/v4/projects/${{ secrets.PROJECT_ID }}/trigger/pipeline" build-acceptance-image: @@ -100,7 +94,7 @@ jobs: uses: docker/setup-buildx-action@v2 - name: Login to Registry - uses: docker/login-action@v1 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} @@ -110,15 +104,15 @@ jobs: id: get_image_id run: | IMAGE_ID=$(echo ghcr.io/${{ github.repository }}-acceptance | tr '[A-Z]' '[a-z]') - echo ::set-output name=IMAGE_ID::$IMAGE_ID + echo "IMAGE_ID=$IMAGE_ID" >> "$GITHUB_ENV" + + - name: Get the version PR + run: echo "VERSION=${{ github.head_ref }}" >> "$GITHUB_ENV" + if: github.event_name == 'pull_request' - name: Get the version - id: get_version - run: | - VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') - [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') - [ "$VERSION" == "main" ] && VERSION=latest - echo ::set-output name=VERSION::$VERSION + run: echo "VERSION=${{ github.ref_name }}" >> "$GITHUB_ENV" + if: github.event_name != 'pull_request' - name: Build and push container image uses: docker/build-push-action@v3 @@ -126,5 +120,5 @@ jobs: context: . file: ./Dockerfile.acceptance push: true - tags: ${{ steps.get_image_id.outputs.IMAGE_ID }}:${{ steps.get_version.outputs.VERSION }} + tags: ${{ env.IMAGE_ID }}:${{ env.VERSION }} platforms: linux/amd64,linux/arm64 diff --git a/.github/workflows/build_development.yml b/.github/workflows/build_development.yml index 25ce314..704ca80 100644 --- a/.github/workflows/build_development.yml +++ b/.github/workflows/build_development.yml @@ -22,22 +22,20 @@ jobs: uses: docker/setup-buildx-action@v2 - name: Login to Registry - uses: docker/login-action@v1 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Get the image id - id: get_image_id run: | IMAGE_ID=$(echo ghcr.io/${{ github.repository }} | tr '[A-Z]' '[a-z]') - echo ::set-output name=IMAGE_ID::$IMAGE_ID + echo "IMAGE_ID=$IMAGE_ID" >> "$GITHUB_ENV" - name: Extract branch name shell: bash - run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT - id: extract_branch + run: echo "IMAGE_BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> "$GITHUB_ENV" - name: Build and push container image uses: docker/build-push-action@v3 @@ -45,5 +43,5 @@ jobs: context: . file: ./Dockerfile.development push: true - tags: ${{ steps.get_image_id.outputs.IMAGE_ID }}:${{ steps.extract_branch.outputs.branch }}_development + tags: ${{ env.IMAGE_ID}}:${{ env.IMAGE_BRANCH }}_development platforms: linux/amd64,linux/arm64