Skip to content

Commit 4a5c1f2

Browse files
authored
Merge pull request #14 from AlexAtkinson/ops/docs
Fix example
2 parents fcc5e4d + 35311b7 commit 4a5c1f2

File tree

2 files changed

+69
-15
lines changed

2 files changed

+69
-15
lines changed

README.md

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
![license](https://img.shields.io/github/license/AlexAtkinson/github-action-gitops-autover?style=flat-square)
55
![language](https://img.shields.io/github/languages/top/AlexAtkinson/github-action-gitops-autover?style=flat-square)
66
![repo size](https://img.shields.io/github/repo-size/AlexAtkinson/github-action-gitops-autover?style=flat-square)
7-
![Count of Action Users](https://img.shields.io/endpoint?url=https://AlexAtkinson.github.io/github-action-gitops-autover/github-action-gitops-autover.json&style=flat-square)
7+
<!-- ![Count of Action Users](https://img.shields.io/endpoint?url=https://AlexAtkinson.github.io/github-action-gitops-autover/github-action-gitops-autover.json&style=flat-square) -->
88
<!-- https://github.com/marketplace/actions/count-action-users -->
99
<!-- ![HitCount](https://hits.dwyl.com/AlexAtkinson/github-action-gitops-autover.svg?style=flat-square) -->
1010

@@ -32,11 +32,12 @@ git push --tags</pre></dd>
3232
<dt>Workflow Setup</dt>
3333
<dd>2. Ensure your action executes a checkout step prior to using this action.</dd>
3434
<dd>3. Use the outputs from this action as desired. For example, you might use it to update the version of an npm package:</dd>
35-
<dd><pre>
36-
npm version $NEW_VERSION</pre></dd>
35+
<dd>
36+
<pre>npm version ${{ steps.gitops-autover.outputs.new-version }}</pre>
37+
</dd>
3738
<dd>4. Tag the repo with the new version at some point in the workflow.
3839
<dt>Team Setup</dt>
39-
<dd>5. Ensure the iteration team adheres to the branch naming scheme defined below. Here's an example workflow.</dd>
40+
<dd>5. Ensure the iteration team adheres to the branch naming scheme defined below. Here's an example workflow. Bonus points for integrating branch management into your issue tracking system.</dd>
4041
<dd><pre>
4142
git checkout -b fix/not-a-feature
4243
git commit --allow-empty -m "This was a bug and not a feature after all..."
@@ -53,7 +54,7 @@ git push --set-upstream origin fix/not-a-feature
5354
<dd>The previous version.</dd>
5455
</dl>
5556

56-
### Example GH Action Workflow
57+
### Example GH Action Workflows
5758

5859
Below is a valid workflow utilizing this action. If you wanted to extend it to do something like update a 'package.json' version, for example, you would simply create a step that runs: `npm version $NEW_VERSION`.
5960

@@ -100,6 +101,56 @@ _minor:_
100101
101102
Additionally, this repo uses its own action for versioning, so feel free to investigate that workflow for another example.
102103

104+
### A More Complete Example
105+
106+
name: gitops-autover-example
107+
on:
108+
push:
109+
branches:
110+
- main
111+
jobs:
112+
init:
113+
name: Initialize
114+
runs-on: ubuntu-latest
115+
outputs:
116+
REPOSITORY: ${{ steps.init.outputs.REPOSITORY }}
117+
PRODUCT: ${{ steps.init.outputs.PRODUCT_NAME }}
118+
PRODUCT_NAME_LOWER: ${{ steps.init.outputs.PRODUCT_NAME_LOWER }}
119+
NEW_VERSION: ${{ steps.gitops-autover.outputs.new-version }}
120+
PREVIOUS_VERSION: ${{ steps.gitops-autover.outputs.previous-version }}
121+
steps:
122+
- name: Checkout Source
123+
uses: actions/checkout@v3
124+
with:
125+
lfs: true
126+
fetch-depth: 0
127+
- name: Initialize
128+
id: init
129+
run: |
130+
# Detect repo name.
131+
REPOSITORY=${PWD##*/}
132+
echo "REPOSITORY=$REPOSITORY" >> $GITHUB_OUTPUT
133+
# Autodetect product name. Eg:
134+
# A repo named cool-corp-awesome-docker will result in
135+
# the image being pushed as: awesome-docker:x.x.x
136+
[[ $(echo -n "$(cut -d- -f3- <<< ${REPOSITORY})" | wc -c) -gt 0 ]] && PRODUCT_NAME=$(cut -d- -f3- <<< ${REPOSITORY})
137+
[[ $(echo -n "$(cut -d- -f3- <<< ${REPOSITORY})" | wc -c) -eq 0 ]] && PRODUCT_NAME=default
138+
echo "PRODUCT_NAME=$PRODUCT_NAME" >> $GITHUB_OUTPUT
139+
PRODUCT_NAME_LOWER=${PRODUCT_NAME,,}
140+
echo "PRODUCT_NAME_LOWER=$PRODUCT_NAME_LOWER" >> $GITHUB_OUTPUT
141+
- name: GitOps Automatic Versioning
142+
id: gitops-autover
143+
uses: AlexAtkinson/[email protected]
144+
build:
145+
name: "Build"
146+
runs-on: ubuntu-latest
147+
needs: [init]
148+
steps:
149+
- name: "Build"
150+
run: |
151+
echo "SUCCESSFUL BUILD" > "${{ needs.init.outputs.PRODUCT_NAME_LOWER }}.${{ needs.init.outputs.NEW_VERSION }}.txt"
152+
# Then bolt on extras such as slack notify or github release actions as needed.
153+
103154
## Discipline Dependency
104155

105156
### Branch Naming Scheme
@@ -123,9 +174,13 @@ This action is _most_ suitable for git projects with the following operational d
123174

124175
- Each merge into main|master is intended to produce an artifact, following the "everything is potentially releasabe" approach.
125176

126-
This action is _not_ suitable for projects requiring pre-release, beta, etc., type fields. Such projects should depend upon their own language native tooling.
127-
128-
This action is _not_ suitable for projects requiring version numbers to be planned and orchestrated ahead of time.
177+
This action is _not_ suitable for projects requiring:
178+
- pre-release, beta, etc., type fields. Such projects should depend upon their own language native tooling.
179+
- specific version numbers to be planned and orchestrated ahead of time (usually marketing efforts).
180+
- Exception: Major releases. These can be actioned on demand as outlined below.
181+
- rebase merges. Reminder: this action _depends_ on merge commit messages.
182+
- Exception: Patterns like: main < (merge-commit) < staging-branch < (rebase) work-branches
183+
- As long as main|master gets a merge commit message, everyone is happy.
129184

130185
## Version Format
131186

scripts/detectNewVersion.sh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ while getopts "he:vfp" opt; do
9797
;;
9898
*)
9999
echo -e "\e[01;31mERROR\e[00m: 570 - Invalid argument!"
100+
echo "::error title=Argument Error::ERROR 570 - Invalid argument!"
100101
printHelp
101102
if [[ "$sourced" == 0 ]]; then
102103
exit 0
@@ -154,6 +155,7 @@ case "$origin_host" in
154155
;;
155156
*)
156157
echo -e "\e[01;31mERROR\e[0m: 591 - Unsupported origin host."
158+
echo "::error title=Origin Host Error::ERROR 591 - Unsupported origin host!"
157159
exit 1
158160
;;
159161
esac
@@ -164,7 +166,8 @@ esac
164166

165167
if [[ -n $arg_e ]]; then
166168
if [[ "$sourced" == 0 ]]; then
167-
echo -e "[$(${tsCmd})] \e[01;31mERROR\e[00m: You must source this script when specifying an environment variable! Eg: '. ./${0##*/} -e foo_ver'\n"
169+
echo -e "[$(${tsCmd})] \e[01;31mERROR\e[00m: 520 - You must source this script when specifying an environment variable! Eg: '. ./${0##*/} -e foo_ver'\n"
170+
echo "::error title=Usage Error::ERROR 520 - You must source this script when specifying an environment variable! Eg: '. ./foo.sh -e bar_ver'"
168171
exit 1
169172
fi
170173
fi
@@ -205,12 +208,8 @@ if [[ -n $arg_f ]]; then
205208
else
206209
if [[ -z $incrementMajor && -z $count_feature && -z $count_enhancement && -z $count_fix && -z $count_bugfix && -z $count_hotfix && -z $count_ops ]]; then
207210
echo -e "\e[01;31mERROR\e[00m: 599 - No feature, enhancement, fix, bugfix, hotfix, or ops branches detected!"
208-
exit 1 # For GH Actions
209-
if [[ "$sourced" == 0 ]]; then
210-
exit 1
211-
else
212-
return 1
213-
fi
211+
echo "::error title=No Valid Merge Detected::ERROR 599 - No feature, enhancement, fix, bugfix, hotfix, or ops branches detected!"
212+
exit 1
214213
fi
215214
fi
216215

0 commit comments

Comments
 (0)