increase version number #332
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
push: | |
paths-ignore: | |
- '**/**.md' | |
- 'documentation/**' | |
env: | |
MAJOR_MINOR_PATCH: 0.5.3 | |
GIN_MODE: release | |
MAIN_PACKAGE: 'cmd/file-store-svc/main.go' | |
concurrency: ci-${{ github.ref }} | |
name: restaurant-file-store-svc-ci | |
jobs: | |
ci: | |
name: ci | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: '^1.22.2' | |
cache: true | |
- name: "Installed go version" | |
run: go version | |
- name: Version suffix | |
id: version_suffix | |
run: | | |
if [[ ${{ github.event_name }} == 'pull_request' ]]; then | |
echo 'for pull request pipeline' | |
USE=true | |
SUFFIX=${GITHUB_HEAD_REF##*/}.${{github.run_number}} | |
EXTENSION="-${SUFFIX}" | |
else | |
if [[ ${{ github.ref }} == "refs/heads/${{ github.event.repository.default_branch }}" ]]; then | |
echo 'for default branch pipeline' | |
USE=false | |
SUFFIX='' | |
EXTENSION='' | |
else | |
echo 'for feature branch pipeline' | |
USE=true | |
SUFFIX=${GITHUB_REF##*/}.${{github.run_number}} | |
EXTENSION="-${SUFFIX}" | |
fi | |
fi | |
echo 'use_version_suffix' $USE | |
echo 'version_suffix: ' $SUFFIX | |
echo "use_version_suffix=$USE" >> $GITHUB_OUTPUT | |
echo "version_suffix=$SUFFIX" >> $GITHUB_OUTPUT | |
echo "extension=$EXTENSION" >> $GITHUB_OUTPUT | |
- name: Semantic version | |
id: semantic_version | |
run: | | |
SEMANTIC_VERSION="${{ env.MAJOR_MINOR_PATCH }}" | |
SEMANTIC_VERSION="${SEMANTIC_VERSION}${{ steps.version_suffix.outputs.extension }}" | |
echo 'MAJOR_MINOR_PATCH: ' $MAJOR_MINOR_PATCH | |
echo 'SEMANTIC_VERSION: ' $SEMANTIC_VERSION | |
echo "semantic_version=$SEMANTIC_VERSION" >> $GITHUB_OUTPUT | |
echo "major_minor_patch=$MAJOR_MINOR_PATCH" >> $GITHUB_OUTPUT | |
- name: "Version upgraded?" | |
id: version_check | |
run: | | |
git fetch --prune --unshallow --tags > /dev/null 2>&1 | |
last_main_version=$(git tag --list 'v[0-9]*\.[0-9]*\.[0-9]*' | grep -Pv "v[0-9]*\.[0-9]*\.[0-9]*-" | sort -V | tail -n 1) | |
echo "Compare last main version: $last_main_version with current version: v$MAJOR_MINOR_PATCH" | |
if [[ $(echo -e "v$MAJOR_MINOR_PATCH\n$last_main_version" | sort -V | head -n 1) == "v$MAJOR_MINOR_PATCH" ]]; then | |
echo "Please upgrade the version number to a higher value than $last_main_version" | |
exit 1 | |
fi | |
- name: Write version txt | |
id: version_txt | |
run: | | |
tee build/version.txt <<< ${{ steps.semantic_version.outputs.semantic_version }} | |
- name: "Build" | |
run: | | |
go build -o bin/app ./${{ env.MAIN_PACKAGE }} | |
- name: "UnitTest" | |
run: | | |
go test ./... -race -coverpkg=all -coverprofile=unit_coverage.out -timeout 5m --tags=unit | |
- name: Create docker network | |
run: 'docker network create restaurant' | |
- name: Start system under test | |
run: docker compose -f scripts/sut/sut-compose.yml up --wait --quiet-pull | |
- name: "ComponentTest" | |
run: | | |
go test ./... -race -coverpkg=all -coverprofile=component_coverage.out -timeout=5m --tags=component | |
- name: "AcceptanceTest" | |
run: | | |
go test ./... -race -coverpkg=all -coverprofile=acceptance_coverage.out -timeout=5m --tags=acceptance --parallel 1 | |
- name: Show system under test logs | |
if: always() | |
run: docker compose -f scripts/sut/sut-compose.yml logs | |
- name: Stop system under test | |
if: always() | |
run: docker compose -f scripts/sut/sut-compose.yml down --volumes | |
- name: "Exclude codecoverage and combine coverage files" # known bug that files parameter is ignored https://github.com/codecov/codecov-action/issues/1285 so unfiltered files must be overriden | |
run: | | |
grep -v -E -f .covignore unit_coverage.out > unit_coverage.filtered.out | |
mv unit_coverage.filtered.out unit_coverage.out | |
grep -v -E -f .covignore component_coverage.out > component_coverage.filtered.out | |
mv component_coverage.filtered.out component_coverage.out | |
grep -v -E -f .covignore acceptance_coverage.out > acceptance_coverage.filtered.out | |
mv acceptance_coverage.filtered.out acceptance_coverage.out | |
- name: "Code coverage" # known bug that files parameter is ignored https://github.com/codecov/codecov-action/issues/1285, upload all files | |
uses: codecov/codecov-action@v4 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
fail_ci_if_error: true | |
- name: "Build artifacts" | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ./build/dockerfile | |
push: false | |
tags: ${{ steps.semantic_version.outputs.semantic_version }} # on push later | |
- name: Create semantic versioning git tag for golang | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
github.rest.git.createRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: "refs/tags/v${{ steps.semantic_version.outputs.semantic_version }}", | |
sha: context.sha | |
}) |