Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add perform release action #10

Merged
merged 2 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .github/workflows/perform_release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Perform Release

on:
workflow_dispatch

jobs:
release:
runs-on: ubuntu-20.04

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Change versions
run: |
# Get version from file
VERSION=$(grep -oE 'const Version = "[0-9]+\.[0-9]+\.[0-9]+-SNAPSHOT"' internal/project/project.go | grep -oE '[0-9]+\.[0-9]+\.[0-9]+-SNAPSHOT')
MAJOR=$(echo $VERSION | grep -oE '^[0-9]+')
MINOR=$(echo $VERSION | grep -oE '\.[0-9]+\.' | grep -oE '[0-9]+')
PATCH=$(echo $VERSION | grep -oE '[0-9]+$' | grep -oE '[0-9]+')

# Remove the -SNAPSHOT suffix
NEW_VERSION="$MAJOR.$MINOR.$PATCH"

# Replace version in first file
sed -i -E "s/const Version = \"[0-9]+\.[0-9]+\.[0-9]+-SNAPSHOT\"/const Version = \"$NEW_VERSION\"/" internal/project/project.go

# Replace version in second file
sed -i -E "s/ <version>[0-9]+\.[0-9]+\.[0-9]+-SNAPSHOT<\/version>/ <version>$NEW_VERSION<\/version>/" java/pom.xml

# Replace version in third file
sed -i -E "s/ <PackageVersion>[0-9]+\.[0-9]+\.[0-9]+-SNAPSHOT<\/PackageVersion>/ <PackageVersion>$NEW_VERSION<\/PackageVersion>/" csharp/Deckard.csproj

echo "deckard_new_version=$NEW_VERSION" >> $GITHUB_ENV
echo "deckard_old_version=$VERSION" >> $GITHUB_ENV
echo "deckard_major=$MAJOR" >> $GITHUB_ENV
echo "deckard_minor=$MINOR" >> $GITHUB_ENV
echo "deckard_patch=$PATCH" >> $GITHUB_ENV

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: 'build: ${{ env.deckard_new_version }} release'
file_pattern: 'internal/project/project.go java/pom.xml csharp/Deckard.csproj'

- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
tag_name: ${{ env.deckard_new_version }}
generate_release_notes: true

- name: Add -SNAPSHOT suffix
run: |
# Increase patch version and add -SNAPSHOT suffix
NEW_PATCH=$(($PATCH + 1))
NEW_SNAPSHOT_VERSION="$MAJOR.$MINOR.$NEW_PATCH-SNAPSHOT"

# Replace version in first file
sed -i -E "s/const Version = \"[0-9]+\.[0-9]+\.[0-9]+\"/const Version = \"$NEW_SNAPSHOT_VERSION\"/" internal/project/project.go

# Replace version in second file
sed -i -E "s/ <version>[0-9]+\.[0-9]+\.[0-9]+<\/version>/ <version>$NEW_SNAPSHOT_VERSION<\/version>/" java/pom.xml

# Replace version in third file
sed -i -E "s/ <PackageVersion>[0-9]+\.[0-9]+\.[0-9]+<\/PackageVersion>/ <PackageVersion>$NEW_SNAPSHOT_VERSION<\/PackageVersion>/" csharp/Deckard.csproj

echo "deckard_new_snapshot_version=$NEW_SNAPSHOT_VERSION" >> $GITHUB_ENV

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: 'chore: ${{ env.deckard_new_snapshot_version }} release'
file_pattern: 'internal/project/project.go java/pom.xml csharp/Deckard.csproj'
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ jobs:
with:
go-version: ${{ env.GO_VERSION }}

- uses: actions/checkout@v3

- name: Cache Go modules
uses: actions/cache@v3
with:
Expand All @@ -72,8 +74,6 @@ jobs:
- name: Setup Ko
uses: ko-build/setup-ko@v0.6

- uses: actions/checkout@v3

- name: Publish image
env:
auth_token: ${{ secrets.DOCKER_HUB_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
with:
go-version: ${{ env.GO_VERSION }}

- uses: actions/checkout@v3

- name: Cache Go modules
uses: actions/cache@v3
with:
Expand All @@ -36,8 +38,6 @@ jobs:
restore-keys: |
${{ runner.os }}-golang-

- uses: actions/checkout@v3

- name: Install mockgen
run: go install github.com/golang/mock/mockgen@latest

Expand Down