From 43e24c5ae63cefdac4784b330948f98cba6ab68a Mon Sep 17 00:00:00 2001 From: David Bloss Date: Wed, 18 Jan 2023 11:23:13 -0600 Subject: [PATCH] update gh action set-output variables (#6635) * update gh action set-output variables * add changie file --- .../Under the Hood-20230117-111737.yaml | 6 ++++++ .github/_README.md | 20 +++++++++---------- .github/actions/latest-wrangler/main.py | 17 +++++++++------- .github/workflows/main.yml | 8 ++++++-- .github/workflows/release-docker.yml | 12 ++++++----- .github/workflows/release.yml | 2 +- .github/workflows/version-bump.yml | 2 +- 7 files changed, 41 insertions(+), 26 deletions(-) create mode 100644 .changes/unreleased/Under the Hood-20230117-111737.yaml diff --git a/.changes/unreleased/Under the Hood-20230117-111737.yaml b/.changes/unreleased/Under the Hood-20230117-111737.yaml new file mode 100644 index 00000000000..126a25ea28a --- /dev/null +++ b/.changes/unreleased/Under the Hood-20230117-111737.yaml @@ -0,0 +1,6 @@ +kind: Under the Hood +body: Update deprecated github action command +time: 2023-01-17T11:17:37.046095-06:00 +custom: + Author: davidbloss + Issue: "6153" diff --git a/.github/_README.md b/.github/_README.md index 4da081fe2b6..f624fc5fec6 100644 --- a/.github/_README.md +++ b/.github/_README.md @@ -63,12 +63,12 @@ permissions: contents: read pull-requests: write ``` - + ### Secrets - When to use a [Personal Access Token (PAT)](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) vs the [GITHUB_TOKEN](https://docs.github.com/en/actions/security-guides/automatic-token-authentication) generated for the action? The `GITHUB_TOKEN` is used by default. In most cases it is sufficient for what you need. - + If you expect the workflow to result in a commit to that should retrigger workflows, you will need to use a Personal Access Token for the bot to commit the file. When using the GITHUB_TOKEN, the resulting commit will not trigger another GitHub Actions Workflow run. This is due to limitations set by GitHub. See [the docs](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow) for a more detailed explanation. For example, we must use a PAT in our workflow to commit a new changelog yaml file for bot PRs. Once the file has been committed to the branch, it should retrigger the check to validate that a changelog exists on the PR. Otherwise, it would stay in a failed state since the check would never retrigger. @@ -105,7 +105,7 @@ Some triggers of note that we use: ``` # **what?** - # Describe what the action does. + # Describe what the action does. # **why?** # Why does this action exist? @@ -138,7 +138,7 @@ Some triggers of note that we use: id: fp run: | FILEPATH=.changes/unreleased/Dependencies-${{ steps.filename_time.outputs.time }}.yaml - echo "::set-output name=FILEPATH::$FILEPATH" + echo "FILEPATH=$FILEPATH" >> $GITHUB_OUTPUT ``` - Print out all variables you will reference as the first step of a job. This allows for easier debugging. The first job should log all inputs. Subsequent jobs should reference outputs of other jobs, if present. @@ -158,14 +158,14 @@ Some triggers of note that we use: echo "The build_script_path: ${{ inputs.build_script_path }}" echo "The s3_bucket_name: ${{ inputs.s3_bucket_name }}" echo "The package_test_command: ${{ inputs.package_test_command }}" - + # collect all the variables that need to be used in subsequent jobs - name: Set Variables id: variables run: | - echo "::set-output name=important_path::'performance/runner/Cargo.toml'" - echo "::set-output name=release_id::${{github.event.inputs.release_id}}" - echo "::set-output name=open_prs::${{github.event.inputs.open_prs}}" + echo "important_path='performance/runner/Cargo.toml'" >> $GITHUB_OUTPUT + echo "release_id=${{github.event.inputs.release_id}}" >> $GITHUB_OUTPUT + echo "open_prs=${{github.event.inputs.open_prs}}" >> $GITHUB_OUTPUT job2: needs: [job1] @@ -190,7 +190,7 @@ ___ ### Actions from the Marketplace - Don’t use external actions for things that can easily be accomplished manually. - Always read through what an external action does before using it! Often an action in the GitHub Actions Marketplace can be replaced with a few lines in bash. This is much more maintainable (and won’t change under us) and clear as to what’s actually happening. It also prevents any -- Pin actions _we don't control_ to tags. +- Pin actions _we don't control_ to tags. ### Connecting to AWS - Authenticate with the aws managed workflow @@ -208,7 +208,7 @@ ___ ```yaml - name: Copy Artifacts from S3 via CLI - run: aws s3 cp ${{ env.s3_bucket }} . --recursive + run: aws s3 cp ${{ env.s3_bucket }} . --recursive ``` ### Testing diff --git a/.github/actions/latest-wrangler/main.py b/.github/actions/latest-wrangler/main.py index 23e14cf5abe..db91cf8354b 100644 --- a/.github/actions/latest-wrangler/main.py +++ b/.github/actions/latest-wrangler/main.py @@ -28,11 +28,12 @@ if package_request.status_code == 404: if halt_on_missing: sys.exit(1) - else: - # everything is the latest if the package doesn't exist - print(f"::set-output name=latest::{True}") - print(f"::set-output name=minor_latest::{True}") - sys.exit(0) + # everything is the latest if the package doesn't exist + github_output = os.environ.get("GITHUB_OUTPUT") + with open(github_output, "at", encoding="utf-8") as gh_output: + gh_output.write("latest=True") + gh_output.write("minor_latest=True") + sys.exit(0) # TODO: verify package meta is "correct" # https://github.com/dbt-labs/dbt-core/issues/4640 @@ -91,5 +92,7 @@ def is_latest( latest = is_latest(pre_rel, new_version, current_latest) minor_latest = is_latest(pre_rel, new_version, current_minor_latest) - print(f"::set-output name=latest::{latest}") - print(f"::set-output name=minor_latest::{minor_latest}") + github_output = os.environ.get("GITHUB_OUTPUT") + with open(github_output, "at", encoding="utf-8") as gh_output: + gh_output.write(f"latest={latest}") + gh_output.write(f"minor_latest={minor_latest}") diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8138b730d34..c8347f6b069 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -101,7 +101,9 @@ jobs: - name: Get current date if: always() id: date - run: echo "::set-output name=date::$(date +'%Y-%m-%dT%H_%M_%S')" #no colons allowed for artifacts + run: | + CURRENT_DATE=$(date +'%Y-%m-%dT%H_%M_%S') # no colons allowed for artifacts + echo "date=$CURRENT_DATE" >> $GITHUB_OUTPUT - uses: actions/upload-artifact@v2 if: always() @@ -168,7 +170,9 @@ jobs: - name: Get current date if: always() id: date - run: echo "::set-output name=date::$(date +'%Y_%m_%dT%H_%M_%S')" #no colons allowed for artifacts + run: | + CURRENT_DATE=$(date +'%Y-%m-%dT%H_%M_%S') # no colons allowed for artifacts + echo "date=$CURRENT_DATE" >> $GITHUB_OUTPUT - uses: actions/upload-artifact@v2 if: always() diff --git a/.github/workflows/release-docker.yml b/.github/workflows/release-docker.yml index f47f110aeb1..f7b8dc29543 100644 --- a/.github/workflows/release-docker.yml +++ b/.github/workflows/release-docker.yml @@ -41,9 +41,9 @@ jobs: id: version run: | IFS="." read -r MAJOR MINOR PATCH <<< ${{ github.event.inputs.version_number }} - echo "::set-output name=major::$MAJOR" - echo "::set-output name=minor::$MINOR" - echo "::set-output name=patch::$PATCH" + echo "major=$MAJOR" >> $GITHUB_OUTPUT + echo "minor=$MINOR" >> $GITHUB_OUTPUT + echo "patch=$PATCH" >> $GITHUB_OUTPUT - name: Is pkg 'latest' id: latest @@ -70,8 +70,10 @@ jobs: - name: Get docker build arg id: build_arg run: | - echo "::set-output name=build_arg_name::"$(echo ${{ github.event.inputs.package }} | sed 's/\-/_/g') - echo "::set-output name=build_arg_value::"$(echo ${{ github.event.inputs.package }} | sed 's/postgres/core/g') + BUILD_ARG_NAME=$(echo ${{ github.event.inputs.package }} | sed 's/\-/_/g') + BUILD_ARG_VALUE=$(echo ${{ github.event.inputs.package }} | sed 's/postgres/core/g') + echo "build_arg_name=$BUILD_ARG_NAME" >> $GITHUB_OUTPUT + echo "build_arg_value=$BUILD_ARG_VALUE" >> $GITHUB_OUTPUT - name: Log in to the GHCR uses: docker/login-action@v1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1abab3e5013..ade939b6ee3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -165,7 +165,7 @@ jobs: env: IS_PRERELEASE: ${{ contains(github.event.inputs.version_number, 'rc') || contains(github.event.inputs.version_number, 'b') }} run: | - echo ::set-output name=isPrerelease::$IS_PRERELEASE + echo "isPrerelease=$IS_PRERELEASE" >> $GITHUB_OUTPUT - name: Creating GitHub Release uses: softprops/action-gh-release@v1 diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index 1a5be6aefb1..2bbaf1cef82 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -65,7 +65,7 @@ jobs: - name: Set branch value id: variables run: | - echo "::set-output name=BRANCH_NAME::prep-release/${{ github.event.inputs.version_number }}_$GITHUB_RUN_ID" + echo "BRANCH_NAME=prep-release/${{ github.event.inputs.version_number }}_$GITHUB_RUN_ID" >> $GITHUB_OUTPUT - name: Create PR branch run: |