From 5b387aec5fbddace372a4a4506ee32a36b367d18 Mon Sep 17 00:00:00 2001 From: Niall Byrne <9848926+niall-byrne@users.noreply.github.com> Date: Wed, 1 Mar 2023 11:25:48 -0500 Subject: [PATCH] ci(GITHUB): replace push action --- .github/scripts/test_push.sh | 60 +++++++++++++++++++++++++++ .github/workflows/self-test.yml | 72 ++++++++++++--------------------- 2 files changed, 86 insertions(+), 46 deletions(-) create mode 100644 .github/scripts/test_push.sh diff --git a/.github/scripts/test_push.sh b/.github/scripts/test_push.sh new file mode 100644 index 00000000..dedae1d4 --- /dev/null +++ b/.github/scripts/test_push.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +# .github/scripts/test_push.sh +# Performs pushes against the test repository to trigger rendered workflows. + +# 1: The name of the branch you wish to push. +# 2: Optionally set a tag you'd like to push. +# REMOTE_TOKEN: The auth token that will be used to push. +# REMOTE_ORIGIN: The remote repository we're pushing to. (format: "owner/repository") +# TEMPLATED_NAME: The name of the rendered test project. + +# CI only script. + +set -eo pipefail + +add_test_commit() { + echo "test commit" > test_file.txt + git add test_file.txt + git commit -m 'feat(TEST_FILE): add test file' +} + +push() { + # 1: The branch you are pushing. + git push "$(util_get_remote)" HEAD:"${1}" --force +} + +push_tags() { + # 1: The tag you'd like to push + + # Don't push this tag again. + git tag --delete 0.0.0 + + # Ensure remote tag doesn't exist + set +e + git push --delete "$(util_get_remote)" "${1}" + set -e + + git tag "${1}" + git push "$(util_get_remote)" --tags +} + +util_get_remote() { + echo "https://${REMOTE_TOKEN}@github.com/${REMOTE_ORIGIN}.git" +} + +main() { + + pushd "${TEMPLATED_NAME}" + git checkout "${1}" + if [[ -z "${2}" ]]; then + add_test_commit + push "${1}" + else + push_tags "${2}" + fi + popd + +} + +main "$@" diff --git a/.github/workflows/self-test.yml b/.github/workflows/self-test.yml index 89403bf9..ffd87d02 100644 --- a/.github/workflows/self-test.yml +++ b/.github/workflows/self-test.yml @@ -457,12 +457,11 @@ jobs: env: ANSIBLE_WORKBENCH_SKIP_POETRY: 1 ANSIBLE_WORKBENCH_SKIP_PRECOMMIT: 1 - TEMPLATED_NAME_1: "flower-generator-with-toml" - TEMPLATED_NAME_2: "flower-generator-no-toml" TEST_PUSH_TAG: "0.1.0" strategy: max-parallel: 4 matrix: + cookiecutter-toml-selection: [1, 2] python-version: ${{ fromJson(needs._create_configuration.outputs.configuration)._GITHUB_CI_PYTHON_VERSIONS }} steps: @@ -489,69 +488,50 @@ jobs: - name: Push Test -- Render Template run: | - source ./template/.github/scripts/template.sh "1" "GitHub Action" "action@github.com" - mv "${TEMPLATED_NAME}" "${TEMPLATED_NAME_1}" - source ./template/.github/scripts/template.sh "2" "GitHub Action" "action@github.com" - mv "${TEMPLATED_NAME}" "${TEMPLATED_NAME_2}" + source ./template/.github/scripts/template.sh "${SELECTION_TOML}" "GitHub Action" "action@github.com" + env: + SELECTION_TOML: ${{ matrix.cookiecutter-toml-selection }} - name: Push Test -- Clean Up Test Releases + if: matrix.cookiecutter-toml-selection == 1 run: | source ./template/.github/scripts/prune_test_releases.sh env: GITHUB_TOKEN: ${{ secrets.REMOTE_TOKEN }} REMOTE_ORIGIN: ${{ secrets.REMOTE_ORIGIN }} - - name: Push Test -- Clean Up Tags for Git Push (${{ env.TEMPLATED_NAME_1 }}) + - name: Push Test -- Push To Test Repository (${{ env.ANSIBLE_WORKBENCH_BRANCH_NAME_BASE }}) + if: matrix.cookiecutter-toml-selection == 1 run: | - cd ${TEMPLATED_NAME_1} - git checkout "${ANSIBLE_WORKBENCH_BRANCH_NAME_BASE}" - git tag --delete 0.0.0 # Don't Repush + source ./template/.github/scripts/test_push.sh "${ANSIBLE_WORKBENCH_BRANCH_NAME_BASE}" + env: + REMOTE_TOKEN: ${{ secrets.REMOTE_TOKEN }} + REMOTE_ORIGIN: ${{ secrets.REMOTE_ORIGIN }} - - name: Push Test -- Test Commit (${{ env.TEMPLATED_NAME_1 }}) + - name: Push Test -- Push To Test Repository (${{ env.TEST_PUSH_TAG }}) + if: matrix.cookiecutter-toml-selection == 1 run: | - cd "${TEMPLATED_NAME_1}" - echo "test commit" > test_file.txt - git add test_file.txt - git commit -m 'feat(TEST_FILE): add test file' - git tag "${TEST_PUSH_TAG}" - - - name: Push Test -- Push To Test Repository (${{ env.ANSIBLE_WORKBENCH_BRANCH_NAME_BASE }}) (${{ env.TEMPLATED_NAME_1 }}) - uses: ad-m/github-push-action@v0.6.0 - with: - github_token: ${{ secrets.REMOTE_TOKEN }} - branch: ${{ env.ANSIBLE_WORKBENCH_BRANCH_NAME_BASE }} - tags: false - directory: ${{ env.TEMPLATED_NAME_1 }} - repository: ${{ secrets.REMOTE_ORIGIN }} - force: true - - - name: Push Test -- Push To Test Repository (${{ env.ANSIBLE_WORKBENCH_BRANCH_NAME_DEVELOPMENT }}) (${{ env.TEMPLATED_NAME_2 }}) - uses: ad-m/github-push-action@v0.6.0 - with: - github_token: ${{ secrets.REMOTE_TOKEN }} - branch: ${{ env.ANSIBLE_WORKBENCH_BRANCH_NAME_DEVELOPMENT }} - tags: false - directory: ${{ env.TEMPLATED_NAME_2 }} - repository: ${{ secrets.REMOTE_ORIGIN }} - force: true - - - name: Push Test -- Push To Test Repository (release tag) - uses: ad-m/github-push-action@v0.6.0 - with: - github_token: ${{ secrets.REMOTE_TOKEN }} - branch: ${{ env.ANSIBLE_WORKBENCH_BRANCH_NAME_BASE }} - tags: true - directory: ${{ env.TEMPLATED_NAME_1 }} - repository: ${{ secrets.REMOTE_ORIGIN }} - force: true + source ./template/.github/scripts/test_push.sh "${ANSIBLE_WORKBENCH_BRANCH_NAME_BASE}" "${TEST_PUSH_TAG}" + env: + REMOTE_TOKEN: ${{ secrets.REMOTE_TOKEN }} + REMOTE_ORIGIN: ${{ secrets.REMOTE_ORIGIN }} - name: Push Test -- Trigger Release Workflow Test + if: matrix.cookiecutter-toml-selection == 1 run: | gh workflow run -r "${TEST_PUSH_TAG}" -R "${REMOTE_ORIGIN}" release.yml -f "TAG=${TEST_PUSH_TAG}" env: GITHUB_TOKEN: ${{ secrets.REMOTE_TOKEN }} REMOTE_ORIGIN: ${{ secrets.REMOTE_ORIGIN }} + - name: Push Test -- Push To Test Repository (${{ env.ANSIBLE_WORKBENCH_BRANCH_NAME_DEVELOPMENT }}) + if: matrix.cookiecutter-toml-selection == 2 + run: | + source ./template/.github/scripts/test_push.sh "${ANSIBLE_WORKBENCH_BRANCH_NAME_DEVELOPMENT}" + env: + REMOTE_TOKEN: ${{ secrets.REMOTE_TOKEN }} + REMOTE_ORIGIN: ${{ secrets.REMOTE_ORIGIN }} + - name: Push Test -- Report Job Status on Success if: env.VERBOSE_NOTIFICATIONS == '1' run: |