Skip to content

Commit cf0b828

Browse files
committed
Split binaries for git tagging and version calculation to separate scripts
1 parent 8c775c0 commit cf0b828

File tree

4 files changed

+111
-61
lines changed

4 files changed

+111
-61
lines changed

.github/workflows/build.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Publish Docker image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
release:
9+
types: [published]
10+
11+
jobs:
12+
push_to_registry:
13+
name: Push Docker image to Docker Hub
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Check out the repo
17+
uses: actions/checkout@v2
18+
19+
- name: Log in to Docker Hub
20+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
21+
with:
22+
username: ${{ secrets.DOCKER_USERNAME }}
23+
password: ${{ secrets.DOCKER_PASSWORD }}
24+
25+
- name: Extract metadata (tags, labels) for Docker
26+
id: meta
27+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
28+
with:
29+
images: ${{ github.repository }}
30+
31+
- name: Build and push Docker image
32+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
33+
with:
34+
context: .
35+
push: true
36+
tags: ${{ steps.meta.outputs.tags }}
37+
labels: ${{ steps.meta.outputs.labels }}

bin/git-tag

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Check that required variables are defined
5+
test -v GITAUTH_USER || (echo "Missing GITAUTH_USER variable" && exit 1)
6+
test -v GITAUTH_PASS || (echo "Missing GITAUTH_PASS variable" && exit 1)
7+
8+
# Check gitlab variables are set
9+
test -v GITLAB_USER_EMAIL || (echo "Missing GITLAB_USER_EMAIL variable" && exit 1)
10+
test -v GITLAB_USER_NAME || (echo "Missing GITLAB_USER_NAME variable" && exit 1)
11+
test -v CI_REPOSITORY_URL || (echo "Missing CI_REPOSITORY_URL variable" && exit 1)
12+
13+
# Setup git details
14+
echo "Setting git author $GITLAB_USER_NAME <$GITLAB_USER_EMAIL>"
15+
git config --global user.email "$GITLAB_USER_EMAIL"
16+
git config --global user.name "$GITLAB_USER_NAME"
17+
18+
19+
if [ -z "$1" ] ; then
20+
echo "Missing version arg $1"
21+
exit 1
22+
fi
23+
24+
25+
VERSION=$1
26+
27+
echo ""
28+
echo "Creating Git tag '$VERSION'"
29+
git tag $VERSION
30+
31+
# Show graph
32+
git log --all --decorate --oneline --graph -10
33+
34+
# Update remote URL so we can push, then push the tag
35+
echo "Adding auth to $CI_REPOSITORY_URL"
36+
NEW_URL=$(addauth $CI_REPOSITORY_URL $GITAUTH_USER $GITAUTH_PASS)
37+
38+
echo "Updating remote"
39+
ORIGINAL_REMOTE=$(git remote get-url origin)
40+
git remote set-url origin $NEW_URL
41+
42+
echo "Pushing tag $VERSION"
43+
git push origin $VERSION
44+
45+
echo "Resetting remote"
46+
git remote set-url origin $ORIGINAL_REMOTE

bin/next-version

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
# Calculates next version by looking up the last Git tag and comparing it to head
3+
4+
set -e
5+
6+
# Fetch tags
7+
git fetch --tags --prune >/dev/null
8+
9+
# Check for existing tags
10+
if [ "$(git ls-remote --tags | wc -l)" == "0" ] ; then
11+
# Default version
12+
PREV_VERSION='0.0.0'
13+
COMPARE_TO=$(git log --pretty=format:%H | tail -1)
14+
INC='MAJOR'
15+
else
16+
# Lookup latest version
17+
PREV_VERSION=$(latesttag)
18+
COMPARE_TO=$PREV_VERSION
19+
INC=$(php-autosemver $COMPARE_TO)
20+
fi
21+
22+
VERSION=$(composer-version --inc $PREV_VERSION $INC)
23+
24+
echo ${VERSION}

bin/tag

Lines changed: 4 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,7 @@
11
#!/bin/bash
22
set -e
33

4-
# Check for required variables are defined
5-
test -v GITAUTH_USER || (echo "Missing GITAUTH_USER variable" && exit 1)
6-
test -v GITAUTH_PASS || (echo "Missing GITAUTH_PASS variable" && exit 1)
7-
8-
# Check gitlab variables are set
9-
test -v GITLAB_USER_EMAIL || (echo "Missing GITLAB_USER_EMAIL variable" && exit 1)
10-
test -v GITLAB_USER_NAME || (echo "Missing GITLAB_USER_NAME variable" && exit 1)
11-
test -v CI_REPOSITORY_URL || (echo "Missing CI_REPOSITORY_URL variable" && exit 1)
12-
13-
# Setup git details
14-
echo "Setting git author $GITLAB_USER_NAME <$GITLAB_USER_EMAIL>"
15-
git config --global user.email "$GITLAB_USER_EMAIL"
16-
git config --global user.name "$GITLAB_USER_NAME"
17-
18-
# Fetch tags
19-
echo "Fetching tags"
20-
git fetch --tags --prune
21-
# Check for existing tags
22-
if [ "$(git ls-remote --tags | wc -l)" == "0" ] ; then
23-
# Default version
24-
PREV_VERSION='0.0.0'
25-
COMPARE_TO=$(git log --pretty=format:%H | tail -1)
26-
INC='MAJOR'
27-
else
28-
# Lookup latest version
29-
PREV_VERSION=$(latesttag)
30-
COMPARE_TO=$PREV_VERSION
31-
echo "Analysing for next semver version compared to '$PREV_VERSION'"
32-
INC=$(php-autosemver $COMPARE_TO)
33-
fi
34-
35-
echo "Next inc is '$INC'"
36-
37-
echo "Calculating next version from '$PREV_VERSION'"
38-
VERSION=$(composer-version --inc $PREV_VERSION $INC)
39-
40-
echo ""
41-
echo "Current version: $PREV_VERSION"
42-
echo "Increment: $INC"
43-
echo "New version: $VERSION"
44-
45-
echo ""
46-
echo "Creating Git tag '$VERSION'"
47-
git tag $VERSION
48-
49-
# Show graph
50-
git log --all --decorate --oneline --graph -10
51-
52-
# Update remote URL so we can push, then push the tag
53-
echo "Adding auth to $CI_REPOSITORY_URL"
54-
NEW_URL=$(addauth $CI_REPOSITORY_URL $GITAUTH_USER $GITAUTH_PASS)
55-
56-
echo "Updating remote"
57-
ORIGINAL_REMOTE=$(git remote get-url origin)
58-
git remote set-url origin $NEW_URL
59-
60-
echo "Pushing tag $VERSION"
61-
git push origin $VERSION
62-
63-
echo "Resetting remote"
64-
git remote set-url origin $ORIGINAL_REMOTE
4+
VERSION=$(next-version)
5+
echo "VERSION=${VERSION}"
6+
echo "Tagging"
7+
git-tag ${VERSION}

0 commit comments

Comments
 (0)