diff --git a/.github/workflows/perform_release.yaml b/.github/workflows/perform_release.yaml new file mode 100644 index 0000000..a28b799 --- /dev/null +++ b/.github/workflows/perform_release.yaml @@ -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/ [0-9]+\.[0-9]+\.[0-9]+-SNAPSHOT<\/version>/ $NEW_VERSION<\/version>/" java/pom.xml + + # Replace version in third file + sed -i -E "s/ [0-9]+\.[0-9]+\.[0-9]+-SNAPSHOT<\/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/ [0-9]+\.[0-9]+\.[0-9]+<\/version>/ $NEW_SNAPSHOT_VERSION<\/version>/" java/pom.xml + + # Replace version in third file + sed -i -E "s/ [0-9]+\.[0-9]+\.[0-9]+<\/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' diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index b86c8c1..c16f96e 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -59,6 +59,8 @@ jobs: with: go-version: ${{ env.GO_VERSION }} + - uses: actions/checkout@v3 + - name: Cache Go modules uses: actions/cache@v3 with: @@ -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 }} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 356324f..8812773 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -26,6 +26,8 @@ jobs: with: go-version: ${{ env.GO_VERSION }} + - uses: actions/checkout@v3 + - name: Cache Go modules uses: actions/cache@v3 with: @@ -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