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

Commit

Permalink
ci(GITHUB): prefer pure semantic versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
niall-byrne committed Mar 5, 2023
1 parent 6559378 commit 3f928b2
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 20 deletions.
32 changes: 25 additions & 7 deletions .github/workflows/self-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,44 @@ jobs:

steps:
- name: Create Release -- Checkout Repository
if: contains(github.ref, '/tags/v')
uses: actions/checkout@v3

- name: Create Release -- Branch Filter
id: branch_filter
run: |
source ./{{cookiecutter.project_slug}}/.github/scripts/branch_filter.sh "${{ github.event.ref }}"
- name: Create Release -- Checkout Repository (All Commits)
if: steps.branch_filter.outputs.match == 'TRUE'
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Create Release -- Setup Environment
if: contains(github.ref, '/tags/v')
if: steps.branch_filter.outputs.match == 'TRUE'
run: |
source ./{{cookiecutter.project_slug}}/.github/scripts/setup.sh
echo "{}" > package.json
env:
WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}

- name: Create Release -- Install Poetry
if: steps.branch_filter.outputs.match == 'TRUE'
run: |
source ./{{cookiecutter.project_slug}}/.github/scripts/poetry.sh "install-poetry"
- name: Create Release -- Check 'pyproject.toml' Matches Tag
if: steps.branch_filter.outputs.match == 'TRUE'
run: |
source ./{{cookiecutter.project_slug}}/.github/scripts/version.sh
- name: Create Release -- Generate Changelog
if: contains(github.ref, '/tags/v')
if: steps.branch_filter.outputs.match == 'TRUE'
run:
source ./{{cookiecutter.project_slug}}/.github/scripts/changelog.sh

- name: Create Release -- Create Github Release
if: contains(github.ref, '/tags/v')
if: steps.branch_filter.outputs.match == 'TRUE'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -134,7 +152,7 @@ jobs:
prerelease: false

- name: Create Release -- Report Job Status on Success
if: contains(github.ref, '/tags/v')
if: steps.branch_filter.outputs.match == 'TRUE'
run: |
./{{cookiecutter.project_slug}}/.github/scripts/notifications.sh "${NOTIFICATION}" ":white_check_mark: automated release has been created!\nhttps://github.com/${USERNAME}/${PROJECT_NAME}/releases"
Expand Down Expand Up @@ -315,8 +333,8 @@ jobs:
run: |
cd ${TEMPLATED_NAME}
git checkout master
git tag --delete v0.0.0 # Don't Repush
git tag v1.0.0
git tag --delete 0.0.0 # Don't Repush
git tag 0.1.0
- name: Push Test -- Push To Test Repository (master)
uses: ad-m/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion hooks/post_gen_project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ initialize_git() {
git stage .
git commit -m "build(COOKIECUTTER): initial generation"
git symbolic-ref HEAD "refs/heads/${ANSIBLE_WORKBENCH_BRANCH_NAME_BASE}"
git tag v0.0.0
git tag 0.0.0
git checkout -b "${ANSIBLE_WORKBENCH_BRANCH_NAME_DEVELOPMENT}"
mkdir -p files templates

Expand Down
25 changes: 25 additions & 0 deletions {{cookiecutter.project_slug}}/.github/scripts/branch_filter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# .github/scripts/branch_filter.sh
# Evaluates if the current git reference is a release candidate.

# 1: The git reference that created the workflow flow.

# CI only script.

set -eo pipefail

MATCH="FALSE"

main() {

if [[ "${1}" =~ ^refs/tags/[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$ ]] &&
[[ "${1}" != "refs/tags/0.0.0" ]]; then
MATCH="TRUE"
fi

echo "match=${MATCH}" >> "${GITHUB_OUTPUT}"

}

main "$@"
10 changes: 9 additions & 1 deletion {{cookiecutter.project_slug}}/.github/scripts/changelog.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
#!/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)"

TAG="$(git tag -l --sort=refname | grep -E "[0-9]+\.[0-9]+\.[0-9]+" | tail -n 2 | head -n 1)"
CHANGE_LOG_CONTENT="$(npx -q generate-changelog -f - -t "${TAG}")"

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ main() {
echo "PUSHED_COMMIT_RANGE<<EOF"
echo "${PUSHED_COMMIT_RANGE}"
echo "EOF"
} >> "$GITHUB_ENV"
} >> "${GITHUB_ENV}"

}

Expand Down
21 changes: 21 additions & 0 deletions {{cookiecutter.project_slug}}/.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() {

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

}

main "$@"
36 changes: 27 additions & 9 deletions {{cookiecutter.project_slug}}/.github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,44 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Release -- Checkout Repository
if: contains(github.ref, '/tags/v')
- name: Create Release -- Checkout Repository
uses: {% endraw %}{{ cookiecutter._GITHUB_ACTION_CHECKOUT }}{% raw %}

- name: Create Release -- Branch Filter
id: branch_filter
run: |
source .github/scripts/branch_filter.sh "${{ github.event.ref }}"
- name: Create Release -- Checkout Repository (All Commits)
if: steps.branch_filter.outputs.match == 'TRUE'
uses: {% endraw %}{{ cookiecutter._GITHUB_ACTION_CHECKOUT }}{% raw %}
with:
fetch-depth: 0

- name: Release -- Setup Environment
if: contains(github.ref, '/tags/v')
- name: Create Release -- Setup Environment
if: steps.branch_filter.outputs.match == 'TRUE'
run: |
source ./.github/scripts/setup.sh
env:
WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}

- name: Create Release -- Install Poetry
if: steps.branch_filter.outputs.match == 'TRUE'
run: |
source ./.github/scripts/poetry.sh "install-poetry"
- name: Create Release -- Check 'pyproject.toml' Matches Tag
if: steps.branch_filter.outputs.match == 'TRUE'
run: |
source ./.github/scripts/version.sh
- name: Create Release -- Generate Changelog
if: contains(github.ref, '/tags/v')
if: steps.branch_filter.outputs.match == 'TRUE'
run:
source ./.github/scripts/changelog.sh

- name: Create Release -- Create Github Release
if: contains(github.ref, '/tags/v')
if: steps.branch_filter.outputs.match == 'TRUE'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -113,12 +131,12 @@ jobs:
prerelease: false

- name: Create Release -- Report Job Status (Success)
if: contains(github.ref, '/tags/v')
if: steps.branch_filter.outputs.match == 'TRUE'
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":white_check_mark: automated release has been created:\nhttps://github.com/${USERNAME}/${PROJECT_NAME}/releases"
- name: Release -- Report Job Status (Failure)
if: failure() && contains(github.ref, '/tags/v')
- name: Create Release -- Report Job Status (Failure)
if: failure()
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":x: automated release generation failed!"
Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.project_slug}}/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "{{cookiecutter.project_slug}}"
version = "0.0.1"
version = "0.1.0"
description = "{{cookiecutter.description}}"
authors = ["{{cookiecutter.author}} <{{cookiecutter.email}}>"]

Expand Down

0 comments on commit 3f928b2

Please sign in to comment.