Skip to content

Commit

Permalink
improve build workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
tuantrannav committed Aug 2, 2023
1 parent 8a3f7cb commit 41242f5
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 6 deletions.
31 changes: 25 additions & 6 deletions .github/workflows/build-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,40 @@ name: build and publish

on:
push:
paths-ignore:
- "**.md"
- ".gitignore"
- "LICENCE"
- "CODEOWNERS"
branches:
- main

jobs:
build-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-java@v1
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '17.x'
- name: test and build
run: ./gradlew clean build
run: ./build.sh
- name: prepare release
run: ./prepare-release.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: publish
run: ./gradlew -Pversion="$(TZ="Europe/Oslo" date +'%Y%m%d%H%M')" build publish
run: ./gradlew -Pversion="$VERSION_TAG" publish
env:
ORG_GRADLE_PROJECT_githubUser: x-access-token
ORG_GRADLE_PROJECT_githubPassword: ${{ secrets.GITHUB_TOKEN }}
ORG_GRADLE_PROJECT_githubPassword: ${{ secrets.GITHUB_TOKEN }}
- name: create release
uses: ncipollo/release-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag: ${{ env.VERSION_TAG }}
name: ${{ env.VERSION_TAG }}
body: ${{ env.CHANGE_LOG }}
draft: false
prerelease: false

38 changes: 38 additions & 0 deletions prepare-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
set -e

if [ -n "$GITHUB_WORKSPACE" ]; then
git config --global --add safe.directory $GITHUB_WORKSPACE
cd "$GITHUB_WORKSPACE" || exit
fi

GITHUB_URL="https://api.github.com/repos/$GITHUB_REPOSITORY"
VERSION_TAG=$(TZ="Europe/Oslo" date +'%Y%m%d%H%M')
echo "VERSION_TAG=$VERSION_TAG" >> "$GITHUB_ENV"

if ! git describe --abbrev=0 --tags &>/dev/null; then
FIRST_COMMIT=$(git rev-list --max-parents=0 HEAD)
git tag "CD_autocreate_tag" $FIRST_COMMIT
echo "No tags found. Created one on the initial commit"
fi

LATEST_TAG=$(git describe --abbrev=0 --tags)


git remote set-url origin "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
git tag -f $VERSION_TAG
git push -f --tags


LATEST_RELEASE=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/$GITHUB_REPOSITORY/releases/latest" | jq -r '.tag_name')
if [ "$LATEST_RELEASE" = "null" ]; then LATEST_RELEASE=$LATEST_TAG; fi
echo "Found latest release: $LATEST_RELEASE"
GIT_TREE="[$VERSION_TAG](https://github.com/$GITHUB_REPOSITORY/tree/$VERSION_TAG)"
COMPARE_LINK="[Full Changelog](https://github.com/$GITHUB_REPOSITORY/compare/$LATEST_RELEASE...$VERSION_TAG)"
GIT_LOG=$(git log $LATEST_RELEASE..$VERSION_TAG --no-merges --pretty=format:"* %ad %s" -50 --date=short | sed "/^\\s*$/d")
CHANGELOG="$GIT_TREE
$COMPARE_LINK
$GIT_LOG"
echo "CHANGE_LOG<<EOF" >> "$GITHUB_ENV"
echo "$CHANGELOG" >> "$GITHUB_ENV"
echo "EOF" >> "$GITHUB_ENV"

0 comments on commit 41242f5

Please sign in to comment.