From 33fe177ace61551ac7cbbc14da16feab70ada372 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Tue, 20 Dec 2022 21:22:34 -0600 Subject: [PATCH 1/3] Enable pack "Build and Test" workflow without cloning --- .../workflows/enable-pack-build-and-test.yaml | 54 +++++-------------- 1 file changed, 13 insertions(+), 41 deletions(-) diff --git a/.github/workflows/enable-pack-build-and-test.yaml b/.github/workflows/enable-pack-build-and-test.yaml index f862ec18..4d376dc8 100644 --- a/.github/workflows/enable-pack-build-and-test.yaml +++ b/.github/workflows/enable-pack-build-and-test.yaml @@ -40,7 +40,6 @@ jobs: run: | echo "CI_DIR=${{ github.workspace }}/ci" >> ${GITHUB_ENV} echo "TOOLS_DIR=${{ github.workspace }}/exchange-tools" >> ${GITHUB_ENV} - echo "PACKS_PATH=${{ github.workspace }}/packs" >> ${GITHUB_ENV} - name: Checkout ci repo uses: actions/checkout@v2 @@ -68,53 +67,26 @@ jobs: gh workflow enable "${{ github.workflow }}" --repo "${{ github.repository }}" fi - - name: Checkout Pack Repos and enable their Build and Test Workflow + - name: Enable Pack Repos Build and Test Workflow shell: bash env: PACKS_ORG: ${{ env.packs_org }} PACKS_PREFIX: ${{ env.pack_repo_prefix }} run: | - mkdir -p ${PACKS_PATH} - cd ${PACKS_PATH} source ${TOOLS_DIR}/functions.sh for repo_name in $(_gh_list_repo_names ${PACKS_ORG} ${PACKS_PREFIX}); do - echo "::group::Clone ${PACKS_ORG}/${repo_name}" - gh repo clone "${PACKS_ORG}/${repo_name}" - if latestTag=$(git -C ${repo_name} describe --tags `git -C ${repo_name} rev-list --tags --max-count=1`); then - echo latestTag = $latestTag - git -C ${repo_name} checkout $latestTag -b latestTagBranch - fi - echo - echo "::endgroup::" # DELETED notices will not be folded to simplify scanning action output - if [[ -z "$latestTag" ]]; then - rm -rf ${repo_name} - echo "DELETED clone of ${PACKS_ORG}/${repo_name}: missing git tags" - echo "${PACKS_ORG}/${repo_name}" >> ${GITHUB_WORKSPACE}/bad_pack_repos - elif [[ ! -f "./${repo_name}/pack.yaml" ]]; then - rm -rf ${repo_name} - echo "DELETED clone of ${PACKS_ORG}/${repo_name}: missing pack.yaml" - echo "${PACKS_ORG}/${repo_name}" >> ${GITHUB_WORKSPACE}/bad_pack_repos - else - # - # This is not a bad Pack, ensure the Build and Test workflow is active - # - WORKFLOW_PATH="repos/${PACKS_ORG}/${repo_name}/actions/workflows/build_and_test.yaml" - WORKFLOW_NAME="CI" - echo "::group::Ensure ${WORKFLOW_NAME} workflow for ${PACKS_ORG}/${repo_name} is active" - if gh api --silent --method GET ${WORKFLOW_PATH} 2>/dev/null; then - echo "GitHub ${WORKFLOW_NAME} workflow found for ${PACKS_ORG}/${repo_name}" - echo "Setting GitHub ${WORKFLOW_NAME} workflow for ${PACKS_ORG}/${repo_name} to active" - gh workflow enable $WORKFLOW_NAME --repo ${PACKS_ORG}/${repo_name} - if [[ "$(gh api --method GET ${WORKFLOW_PATH} --jq .state)" != "active" ]]; then - echo "::error::Failed enabling GitHub ${WORKFLOW_NAME} workflow for ${PACKS_ORG}/${repo_name}" - fi - else - echo "::warning::No GitHub ${WORKFLOW_NAME} workflow found for ${PACKS_ORG}/${repo_name}" + WORKFLOW_PATH="repos/${PACKS_ORG}/${repo_name}/actions/workflows/build_and_test.yaml" + WORKFLOW_NAME="CI" + echo "::group::Ensure ${WORKFLOW_NAME} workflow for ${PACKS_ORG}/${repo_name} is active" + if gh api --silent --method GET ${WORKFLOW_PATH} 2>/dev/null; then + echo "GitHub ${WORKFLOW_NAME} workflow found for ${PACKS_ORG}/${repo_name}" + echo "Setting GitHub ${WORKFLOW_NAME} workflow for ${PACKS_ORG}/${repo_name} to active" + gh workflow enable "${WORKFLOW_NAME}" --repo ${PACKS_ORG}/${repo_name} + if [[ "$(gh api --method GET ${WORKFLOW_PATH} --jq .state)" != "active" ]]; then + echo "::error::Failed enabling GitHub ${WORKFLOW_NAME} workflow for ${PACKS_ORG}/${repo_name}" fi - echo "::endgroup::" + else + echo "::warning::No GitHub ${WORKFLOW_NAME} workflow found for ${PACKS_ORG}/${repo_name}" fi + echo "::endgroup::" done - if [[ -f ${GITHUB_WORKSPACE}/bad_pack_repos ]]; then - echo "These repos were DELETED. See above for why." - cat ${GITHUB_WORKSPACE}/bad_pack_repos - fi From 9e44b1439b5bc63d10250581541b8bee1ef8b8a1 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Tue, 20 Dec 2022 22:37:49 -0600 Subject: [PATCH 2/3] Use `gh api` instead of `gh workflow` to avoid graphql and use fine-grained PAT --- .github/workflows/enable-pack-build-and-test.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/enable-pack-build-and-test.yaml b/.github/workflows/enable-pack-build-and-test.yaml index 4d376dc8..d6da827c 100644 --- a/.github/workflows/enable-pack-build-and-test.yaml +++ b/.github/workflows/enable-pack-build-and-test.yaml @@ -60,11 +60,13 @@ jobs: # TODO: Make sure this actually constitutes "repository activity" - name: Conditionally set this Workflow to active (attempt to prevent 60d disabling of itself) shell: bash + env: + WORKFLOW_PATH: repos/${{ github.repository }}/actions/workflows/enable-pack-build-and-test.yaml run: | # NOTE: "gh workflow list" does not currently support json output # Relates to: https://github.com/cli/cli/issues/5025 - if [[ $(gh api --method GET "repos/${{ github.repository }}/actions/workflows/enable-pack-build-and-test.yaml" --jq .state) != "active" ]]; then - gh workflow enable "${{ github.workflow }}" --repo "${{ github.repository }}" + if [[ $(gh api --method GET "${WORKFLOW_PATH}" --jq .state) != "active" ]]; then + gh api --method PUT "${WORKFLOW_PATH}/enable" fi - name: Enable Pack Repos Build and Test Workflow @@ -81,7 +83,7 @@ jobs: if gh api --silent --method GET ${WORKFLOW_PATH} 2>/dev/null; then echo "GitHub ${WORKFLOW_NAME} workflow found for ${PACKS_ORG}/${repo_name}" echo "Setting GitHub ${WORKFLOW_NAME} workflow for ${PACKS_ORG}/${repo_name} to active" - gh workflow enable "${WORKFLOW_NAME}" --repo ${PACKS_ORG}/${repo_name} + gh api --method PUT "${WORKFLOW_PATH}/enable" if [[ "$(gh api --method GET ${WORKFLOW_PATH} --jq .state)" != "active" ]]; then echo "::error::Failed enabling GitHub ${WORKFLOW_NAME} workflow for ${PACKS_ORG}/${repo_name}" fi From f41295b04bd8e01da3ceec689384d140b14b65f0 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Wed, 21 Dec 2022 22:27:05 -0600 Subject: [PATCH 3/3] Remove condition from self-enable workflow task --- .github/workflows/enable-pack-build-and-test.yaml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/enable-pack-build-and-test.yaml b/.github/workflows/enable-pack-build-and-test.yaml index d6da827c..ef8da079 100644 --- a/.github/workflows/enable-pack-build-and-test.yaml +++ b/.github/workflows/enable-pack-build-and-test.yaml @@ -58,16 +58,12 @@ jobs: fetch-depth: 1 # TODO: Make sure this actually constitutes "repository activity" - - name: Conditionally set this Workflow to active (attempt to prevent 60d disabling of itself) + - name: Set this Workflow to active (attempt to prevent 60d disabling of itself) shell: bash env: WORKFLOW_PATH: repos/${{ github.repository }}/actions/workflows/enable-pack-build-and-test.yaml run: | - # NOTE: "gh workflow list" does not currently support json output - # Relates to: https://github.com/cli/cli/issues/5025 - if [[ $(gh api --method GET "${WORKFLOW_PATH}" --jq .state) != "active" ]]; then - gh api --method PUT "${WORKFLOW_PATH}/enable" - fi + gh api --method PUT "${WORKFLOW_PATH}/enable" - name: Enable Pack Repos Build and Test Workflow shell: bash