This is an automated email from the ASF dual-hosted git repository. zrhoffman pushed a commit to branch 6.0.x in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
commit cb451fdabad3cba69c1479c329c0bc679e2b882c Author: Zach Hoffman <[email protected]> AuthorDate: Thu Nov 4 17:00:25 2021 +0000 Allow 0 commits between latest release tag and release branch head (#6329) * Allow 0 commits between latest release tag and release branch head * Use jq for JSON filtering * Cache ATS RPMs by latest ATS branch tag and latest branch commit * Convert to composite action * Trigger _CDN-in-a-Box CI_ and _Cache Config integration tests_ workflows when the _fetch-github-branch-sha_ GitHub Action is modified * Install nodejs by URL until nodesource repo is fixed (cherry picked from commit 2c67dbaede5045ea5ae0b8c5ac89d864aa19081f) --- .github/actions/fetch-github-branch-sha/Dockerfile | 25 ----------------- .github/actions/fetch-github-branch-sha/README.md | 23 +++++++++++++--- .github/actions/fetch-github-branch-sha/action.yml | 29 ++++++++++++-------- .../actions/fetch-github-branch-sha/entrypoint.sh | 31 ++++++++++++---------- .github/workflows/cache-config-tests.yml | 18 +++++++------ .github/workflows/ciab.yaml | 18 +++++++------ infrastructure/cdn-in-a-box/bin/ats-version.sh | 3 ++- .../cdn-in-a-box/traffic_portal/Dockerfile | 8 ++++-- 8 files changed, 82 insertions(+), 73 deletions(-) diff --git a/.github/actions/fetch-github-branch-sha/Dockerfile b/.github/actions/fetch-github-branch-sha/Dockerfile deleted file mode 100644 index 98ccfd6..0000000 --- a/.github/actions/fetch-github-branch-sha/Dockerfile +++ /dev/null @@ -1,25 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -# alpine:3.13 -FROM alpine@sha256:08d6ca16c60fe7490c03d10dc339d9fd8ea67c6466dea8d558526b1330a85930 - -RUN apk add --no-cache bash git curl - -COPY entrypoint.sh / - -ENTRYPOINT /entrypoint.sh diff --git a/.github/actions/fetch-github-branch-sha/README.md b/.github/actions/fetch-github-branch-sha/README.md index 5d7a559..846f034 100644 --- a/.github/actions/fetch-github-branch-sha/README.md +++ b/.github/actions/fetch-github-branch-sha/README.md @@ -18,13 +18,28 @@ --> # fetch-github-branch-sha docker action -This action queries for the latest git commit -sha on a github repo branch +This action queries for the latest git commit sha and latest tag on a GitHub repo branch. + +## Inputs + +### `owner` +The owner username or organization owning the GitHub repository containing the branch being queried + +### `repo` +The name of the GitHub repository containing the branch being queried + +### `branch` +The name of the branch being queried ## Outputs -### `sha` and `exit-code` -the commit sha from a github repo branch +### `sha` +the commit sha from a GitHub repo branch + +### `latest-tag` +the latest tag on the branch + +### `exit-code` 0 if the tests passed, 1 otherwise. ## Example usage diff --git a/.github/actions/fetch-github-branch-sha/action.yml b/.github/actions/fetch-github-branch-sha/action.yml index ac4e505..a3f3efd 100644 --- a/.github/actions/fetch-github-branch-sha/action.yml +++ b/.github/actions/fetch-github-branch-sha/action.yml @@ -18,23 +18,30 @@ name: 'fetch-github-branch-sha' description: 'Fetches the most recent commit from a github repository branch' inputs: - owner: + owner: description: 'The owner of the github repository ie, "apache"' required: true - repo: + repo: description: 'The owners github repository ie, "trafficcontrol"' required: true - branch: + branch: description: 'The repository branch to query ie, "8.1.0-branch"' required: true outputs: sha: - description: 'The latest git commit sha' + description: 'The latest git commit sha on the given branch' + value: ${{ steps.entrypoint.outputs.sha }} + latest-tag: + description: 'The latest git tag on the given branch' + value: ${{ steps.entrypoint.outputs.latest-tag }} runs: - using: 'docker' - image: 'Dockerfile' - args: - - ${{ inputs.owner }} - - ${{ inputs.repo }} - - ${{ inputs.branch }} - + using: 'composite' + steps: + - id: entrypoint + env: + # No need to specify these environment variables once actions/runner#665 is fixed + INPUT_OWNER: ${{ inputs.owner }} + INPUT_REPO: ${{ inputs.repo }} + INPUT_BRANCH: ${{ inputs.branch }} + run: "${{ github.action_path }}/entrypoint.sh" + shell: bash diff --git a/.github/actions/fetch-github-branch-sha/entrypoint.sh b/.github/actions/fetch-github-branch-sha/entrypoint.sh index a4fda07..e80a720 100755 --- a/.github/actions/fetch-github-branch-sha/entrypoint.sh +++ b/.github/actions/fetch-github-branch-sha/entrypoint.sh @@ -17,6 +17,8 @@ # specific language governing permissions and limitations # under the License. # +trap 'echo "Error on line ${LINENO} of ${0}"; exit 1' ERR; +set -o errexit -o nounset # verify required environment inputs. if [[ -z ${INPUT_OWNER} || -z ${INPUT_REPO} || -z ${INPUT_BRANCH} ]]; then @@ -25,31 +27,32 @@ if [[ -z ${INPUT_OWNER} || -z ${INPUT_REPO} || -z ${INPUT_BRANCH} ]]; then fi # fetch the branch info -_brinfo=`curl --silent https://api.github.com/repos/${INPUT_OWNER}/${INPUT_REPO}/branches/${INPUT_BRANCH}` -_rc=$? - -if [[ ${_rc} -ne 0 ]]; then +if ! _brinfo="$(curl --silent "${GITHUB_API_URL}/repos/${INPUT_OWNER}/${INPUT_REPO}/branches/${INPUT_BRANCH}")"; then echo "Error: failed to fetch branch info ${INPUT_BRANCH}" exit 2 fi # parse out the commit sha -_sha=`echo -E ${_brinfo} | awk '{ - if ($0 ~ /Branch not found/) { - print "BADBRANCH" - } - else if ($0 ~ /name/) { - print $7 - } -}' | sed -e 's/[",]//g'` +_sha="$(<<<"$_brinfo" jq -r .name)" # verify the sha -if [[ -z ${_sha} || ${_sha} == "BADBRANCH" ]]; then +if [[ -z "${_sha}" || "${_sha}" == "null" ]]; then echo "Error: could not parse the commit from branch ${INPUT_BRANCH}" exit 3 fi echo "::set-output name=sha::${_sha}" -exit 0 +branch_prefix_pattern="^$(<<<"$INPUT_BRANCH" grep -o '.*\.' | sed 's/\./\\./g')[0-9.]+$" + +if ! tags_info="$(curl --silent "${GITHUB_API_URL}/repos/${INPUT_OWNER}/${INPUT_REPO}/tags")"; then + echo "Error: failed to fetch tag info ${INPUT_BRANCH}" + exit 2 +fi +latest_tag="$(<<<"$tags_info" jq -r --arg BRANCH_PREFIX_PATTERN "$branch_prefix_pattern" '.[] | .name | select(test($BRANCH_PREFIX_PATTERN))' | + head -n1)" + +echo "::set-output name=latest-tag::${latest_tag}" + +exit 0 diff --git a/.github/workflows/cache-config-tests.yml b/.github/workflows/cache-config-tests.yml index aad7660..e849eaf 100644 --- a/.github/workflows/cache-config-tests.yml +++ b/.github/workflows/cache-config-tests.yml @@ -31,14 +31,16 @@ on: - GO_VERSION - lib/go-atscfg/**.go - traffic_ops/*client/**.go + - traffic_ops/toclientlib/**.go + - lib/atscfg-go/**.go - traffic_ops/traffic_ops_golang/**.go - cache-config/**.go - cache-config/testing/** - vendor/**.go - vendor/modules.txt - - .github/actions/build-ats-test-rpm - - .github/actions/fetch-github-branch-sha - - .github/actions/cache-config-integration-tests + - .github/actions/build-ats-test-rpm/** + - .github/actions/fetch-github-branch-sha/** + - .github/actions/cache-config-integration-tests/** create: pull_request: paths: @@ -55,9 +57,9 @@ on: - cache-config/testing/** - vendor/**.go - vendor/modules.txt - - .github/actions/build-ats-test-rpm - - .github/actions/fetch-github-branch-sha - - .github/actions/cache-config-integration-tests + - .github/actions/build-ats-test-rpm/** + - .github/actions/fetch-github-branch-sha/** + - .github/actions/cache-config-integration-tests/** types: [opened, reopened, ready_for_review, synchronize] jobs: @@ -100,7 +102,7 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 - - name: Get commit sha + - name: Get latest commit sha and latest tag uses: ./.github/actions/fetch-github-branch-sha with: owner: apache @@ -112,7 +114,7 @@ jobs: uses: actions/cache@v2 with: path: ${{ github.workspace }}/dist - key: ${{ steps.git-repo-sha.outputs.sha }}-el${{ env.RHEL_VERSION }}-${{ hashFiles('cache-config/testing/docker/trafficserver/**') }} + key: ${{ steps.git-repo-sha.outputs.sha }}-${{ steps.git-repo-sha.outputs.latest-tag }}-el${{ env.RHEL_VERSION }}-${{ hashFiles('cache-config/testing/docker/trafficserver/**') }} - name: Build ATS RPM if: steps.ats-rpm-cache.outputs.cache-hit != 'true' uses: ./.github/actions/build-ats-test-rpm diff --git a/.github/workflows/ciab.yaml b/.github/workflows/ciab.yaml index 067d67b..e085840 100644 --- a/.github/workflows/ciab.yaml +++ b/.github/workflows/ciab.yaml @@ -35,9 +35,10 @@ on: - 'docs/**' - 'experimental/**' - '.github/**' - - '!.github/actions/build-ciab/*' - - '!.github/actions/build-rpms/*' - - '!.github/actions/run-ciab/*' + - '!.github/actions/build-ciab/**' + - '!.github/actions/build-rpms/**' + - '!.github/actions/fetch-github-branch-sha/**' + - '!.github/actions/run-ciab/**' - '!infrastructure/cdn-in-a-box/optional/**' - '!.github/workflows/ciab.yaml' - 'infrastructure/ansible/**' @@ -61,9 +62,10 @@ on: - 'docs/**' - 'experimental/**' - '.github/**' - - '!.github/actions/build-ciab/*' - - '!.github/actions/build-rpms/*' - - '!.github/actions/run-ciab/*' + - '!.github/actions/build-ciab/**' + - '!.github/actions/build-rpms/**' + - '!.github/actions/fetch-github-branch-sha/**' + - '!.github/actions/run-ciab/**' - '!infrastructure/cdn-in-a-box/optional/**' - '!.github/workflows/ciab.yaml' - 'infrastructure/ansible/**' @@ -225,7 +227,7 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 - - name: Get commit sha + - name: Get latest commit sha and latest tag uses: ./.github/actions/fetch-github-branch-sha with: owner: apache @@ -237,7 +239,7 @@ jobs: uses: actions/cache@v2 with: path: ${{ github.workspace }}/dist - key: ${{ steps.git-repo-sha.outputs.sha }}-el${{ env.RHEL_VERSION }}-${{ hashFiles('cache-config/testing/docker/trafficserver/**') }} + key: ${{ steps.git-repo-sha.outputs.sha }}-${{ steps.git-repo-sha.outputs.latest-tag }}-el${{ env.RHEL_VERSION }}-${{ hashFiles('cache-config/testing/docker/trafficserver/**') }} - name: Build ATS RPM if: steps.ats-rpm-cache.outputs.cache-hit != 'true' uses: ./.github/actions/build-ats-test-rpm diff --git a/infrastructure/cdn-in-a-box/bin/ats-version.sh b/infrastructure/cdn-in-a-box/bin/ats-version.sh index d9837cc..723a077 100755 --- a/infrastructure/cdn-in-a-box/bin/ats-version.sh +++ b/infrastructure/cdn-in-a-box/bin/ats-version.sh @@ -40,7 +40,8 @@ remote_ats_version() { tail -n1)" # $release is the number of commits between $release to $branch. - release="$(curl -fs "${gitbox_url}?p=${repo};a=shortlog;h=${branch};hp=${last_tag}" | grep -c 'class="link"')" + page_output="$(curl -fs "${gitbox_url}?p=${repo};a=shortlog;h=${branch};hp=${last_tag}")" + release="$(<<<"$page_output" grep -c 'class="link"' || true)" <<<"${last_tag}-${release}.${commit:0:9}" tee "$ats_version_file" } diff --git a/infrastructure/cdn-in-a-box/traffic_portal/Dockerfile b/infrastructure/cdn-in-a-box/traffic_portal/Dockerfile index 4441d91..c9bbbd8 100644 --- a/infrastructure/cdn-in-a-box/traffic_portal/Dockerfile +++ b/infrastructure/cdn-in-a-box/traffic_portal/Dockerfile @@ -37,10 +37,14 @@ ARG TO_HOST=$TO_HOST # Install and delete the TRAFFIC_PORTAL_RPM when finished RUN dnf install -y \ - epel-release && \ + epel-release yum-utils && \ + ### Remove these lines once nodesource/distributions#1290 is fixed + set -o pipefail && \ + yumdownloader -q --url nodejs | xargs dnf -y install && \ + ### dnf install -y \ jq \ - nodejs \ + #nodejs openssl \ gettext \ bind-utils \
