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

Commit

Permalink
ci(GITHUB): upgrade workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
niall-byrne committed Feb 15, 2023
1 parent 5ad944a commit db23d89
Show file tree
Hide file tree
Showing 8 changed files with 249 additions and 126 deletions.
5 changes: 5 additions & 0 deletions .github/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/bin/bash

# .github/scripts/build.sh
# Builds the Python environment to test the project.

# CI only script

set -eo pipefail

main() {
Expand Down
28 changes: 28 additions & 0 deletions .github/scripts/changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# .github/scripts/changelog.sh
# Generates a changelog based off the diff between $TAG and the previous sequential tag.

# TAG: The new git tag the changelog is being generated for.

# CI only script

set -eo pipefail

main() {

echo "{}" > package.json
TAG="$(git tag | sort --version-sort | tail -n 2 | head -n 1)"
CHANGE_LOG_CONTENT="$(npx -q generate-changelog -f - -t "${TAG}")"

{
echo "CHANGE_LOG_CONTENT<<EOF"
echo "${CHANGE_LOG_CONTENT}"
echo "EOF"
} >> "$GITHUB_ENV"

rm package.json

}

main "$@"
20 changes: 16 additions & 4 deletions .github/scripts/notifications.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
#!/bin/bash

# Takes two text arguments
# Message Format: <ARG1>: <ARG2>
# .github/scripts/notifications.sh
# Sends a notification to slack.

[[ -z ${WEBHOOK_URL} ]] && exit 0
curl -X POST -H 'Content-type: application/json' --data "{\"text\":\"${1}: ${2}\"}" "${WEBHOOK_URL}"
# 1: The branch information to display.
# 2: The notification message to send.
# WEBHOOK_URL: The slack webhook url to use.

# CI only script.

main() {

[[ -z ${WEBHOOK_URL} ]] && exit 0
curl -X POST -H 'Content-type: application/json' --data "{\"text\":\"${1}: ${2}\"}" "${WEBHOOK_URL}"

}

main "$@"
40 changes: 40 additions & 0 deletions .github/scripts/pushed_commit_range.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# .github/scripts/pushed_commit_range.sh
# Retrieves the range of the commits in a push, and sets the PUSHED_COMMIT_RANGE environment variables.

# GITHUB_CONTEXT: The github action context object as an environment variable.

# CI only script

set -eo pipefail


get_all_commits() {
git rev-list --max-parents=0 HEAD
}


main() {

PUSHED_COMMIT_RANGE="HEAD~$(echo "$GITHUB_CONTEXT" | jq '.event.commits | length')"

if [[ "${PUSHED_COMMIT_RANGE}" == "HEAD~0" ]]; then
PUSHED_COMMIT_RANGE="$(get_all_commits)"
fi

set +e
if ! git rev-parse "${PUSHED_COMMIT_RANGE}"; then
PUSHED_COMMIT_RANGE="$(get_all_commits)"
fi
set -e

{
echo "PUSHED_COMMIT_RANGE<<EOF"
echo "${PUSHED_COMMIT_RANGE}"
echo "EOF"
} >> "$GITHUB_ENV"

}

main "$@"
18 changes: 13 additions & 5 deletions .github/scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
#!/bin/bash

# shellcheck disable=SC2129
# .github/scripts/setup.sh
# Configures environment variables for Github Actions.

# CI only script.

set -eo pipefail

main() {
BRANCH_OR_TAG="$(echo "${GITHUB_REF}" | sed 's/refs\/heads\///g' | sed 's/refs\/tags\///g')"
WORKFLOW_URL="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
echo "BRANCH_OR_TAG=${BRANCH_OR_TAG}" >> "$GITHUB_ENV"
echo "WEBHOOK_URL=${WEBHOOK_URL}" >> "$GITHUB_ENV"
echo "NOTIFICATION=${PROJECT_NAME} [<${WORKFLOW_URL}|${BRANCH_OR_TAG}>]" >> "$GITHUB_ENV"

{
echo "ANSIBLE_ROLES_PATH=.."
echo "BRANCH_OR_TAG=${BRANCH_OR_TAG}"
echo "WEBHOOK_URL=${WEBHOOK_URL}"
echo "NOTIFICATION=${PROJECT_NAME} [<${WORKFLOW_URL}|${BRANCH_OR_TAG}>]"
} >> "$GITHUB_ENV"

}

main
main "$@"
21 changes: 21 additions & 0 deletions .github/scripts/version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# .github/scripts/version.sh
# Ensures the 'pyproject.toml' version matches the current Git Tag.

# BRANCH_OR_TAG: The name of the current Git Branch or Tag.

# CI only script.

set -eo pipefail

main() {
pip install poetry

if [[ "v$(poetry version -s)" != "${BRANCH_OR_TAG}" ]]; then
echo "The 'pyproject.toml' file does not match the version tag!"
exit 127
fi
}

main "$@"
Loading

0 comments on commit db23d89

Please sign in to comment.