Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
ci(GITHUB): replace push action
Browse files Browse the repository at this point in the history
  • Loading branch information
niall-byrne committed Mar 10, 2023
1 parent 1308de3 commit 5b387ae
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 46 deletions.
60 changes: 60 additions & 0 deletions .github/scripts/test_push.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
72 changes: 26 additions & 46 deletions .github/workflows/self-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -489,69 +488,50 @@ jobs:
- name: Push Test -- Render Template
run: |
source ./template/.github/scripts/template.sh "1" "GitHub Action" "[email protected]"
mv "${TEMPLATED_NAME}" "${TEMPLATED_NAME_1}"
source ./template/.github/scripts/template.sh "2" "GitHub Action" "[email protected]"
mv "${TEMPLATED_NAME}" "${TEMPLATED_NAME_2}"
source ./template/.github/scripts/template.sh "${SELECTION_TOML}" "GitHub Action" "[email protected]"
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/[email protected]
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/[email protected]
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/[email protected]
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: |
Expand Down

0 comments on commit 5b387ae

Please sign in to comment.