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(fix): Fix release workflow #226

Merged
merged 13 commits into from Jul 11, 2022
63 changes: 51 additions & 12 deletions .github/workflows/release.yml
Expand Up @@ -17,13 +17,33 @@ jobs:
env:
CURRENT_VERSION: ${{ github.event.inputs.current_version }}
RELEASE_VERSION: ${{ github.event.inputs.release_version }}
permissions:
contents: write
runs-on: ubuntu-latest

steps:
- name: checkout code
uses: actions/checkout@v2
with:
ref: main

- name: Show initial git status
run: |
echo '### Initial git status' >> $GITHUB_STEP_SUMMARY
echo '```console' >> $GITHUB_STEP_SUMMARY
git status -v >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY

- name: Cache install release tools
id: cache_tools
uses: actions/cache@v2
with:
key: cache_tools_0
path: |
~/.cargo/bin

- name: Install release tools
if: ${{ steps.cache_tools.outputs.cache-hit==false }}
run: |
cargo install cargo-edit toml-cli

Expand All @@ -38,7 +58,7 @@ jobs:
source .github/workflows/scripts/keep-a-changelog.bash
# edit CHANGELOG.md
cp CHANGELOG.md CHANGELOG.md.org
cat CHANGELOG.md.org | bump_changelog "${CURRENT_VERSION}" "${RELEASE_VERSION}" > CHANGELOG.md
cat CHANGELOG.md.org | bump_changelog "v${CURRENT_VERSION}" "v${RELEASE_VERSION}" > CHANGELOG.md
rm CHANGELOG.md.org

- name: bump crate versions
Expand All @@ -57,23 +77,42 @@ jobs:
git add .
git commit -m "update for release v${RELEASE_VERSION}"

- name: cargo publish
- name: Show commit diff
run: |
# TODO: de-comment for login
# cargo login "${{ secrets.CRATES_IO_TOKEN }}"
cargo publish -p springql-core --dry-run # TODO: remove `--dry-run`
cargo publish -p springql --dry-run # TODO: remove `--dry-run`
echo '### Release Commit' >> $GITHUB_STEP_SUMMARY
echo '```diff' >> $GITHUB_STEP_SUMMARY
git diff HEAD^ >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY

- name: git tag
run: |
git tag "v${RELEASE_VERSION}"
git tag "springql@${RELASE_VERSION}"
git tag "springql-core@${RELASE_VERSION}"


- name: Show final git status
run: |
echo '### Final git status' >> $GITHUB_STEP_SUMMARY
echo '```console' >> $GITHUB_STEP_SUMMARY
git status -v >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY

- name: git push
run: |
# TODO: de-comment for push
# git push origin "v${RELEASE_VERSION}"
# git push origin "springql@${RELEASE_VERSION}"
# git push origin "springql-core@${RELEASE_VERSION}"
# git push origin main
git remote set-url origin https://github-actions:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}
git push -v origin main
git push -v origin "v${RELEASE_VERSION}"
git push -v origin "springql@${RELEASE_VERSION}"
git push -v origin "springql-core@${RELEASE_VERSION}"

- name: cargo publish
run: |
# load helper script
source .github/workflows/scripts/crates.io-script.bash

cargo login "${{ secrets.CRATES_IO_TOKEN }}"

cargo publish -p springql-core
wait_published "springql-core" "${RELEASE_VERSION}" 2> /dev/null
cargo publish -p springql
wait_published "springql" "${RELEASE_VERSION}" 2> /dev/null
19 changes: 18 additions & 1 deletion .github/workflows/scripts/crates.io-script.bash
Expand Up @@ -10,4 +10,21 @@ function get_crate_latest_version() {
curl -L https://crates.io/api/v1/crates/$1/versions | jq -r '.versions[] | select( .yanked == false) | .num' | sort --version-sort | tail -n 1
}

export -f get_crate_latest_version
export -f get_crate_latest_version

# function: wait_published
# arg#1: crate name
# arg#2: expect version
function wait_published() {
echo "Waiting $1@$2"
CURRENT_VERSION=$(get_crate_latest_version $1)
echo "CURRENT_VERSION=$CURRENT_VERSION"
while [ $CURRENT_VERSION != "$2" ]
do
sleep 5
CURRENT_VERSION=$(get_crate_latest_version $1)
echo "CURRENT_VERSION=$CURRENT_VERSION"
done
}

export -f wait_published
5 changes: 3 additions & 2 deletions .github/workflows/scripts/keep-a-changelog.bash
Expand Up @@ -8,7 +8,7 @@ function bump_changelog() {
CURRENT_VERSION=$1
NEW_VERSION=$2

while read -r line
while IFS='' read -r line
do
if [ "$line" == "[Unreleased]: https://github.com/SpringQL/SpringQL/compare/${CURRENT_VERSION}...HEAD" ]; then
# update line for [Unreleased]
Expand All @@ -19,7 +19,8 @@ function bump_changelog() {
if [ "$line" == "## [Unreleased]" ]; then
# insert line after ## [Unleleased]
echo # output blank line
echo "## [${NEW_VERSION}]"
RELEASE_DATE=$(date '+%Y-%m-%d')
echo "## [${NEW_VERSION}] - ${RELEASE_DATE}"
fi

if [ "$line" == "[Released]: https://github.com/SpringQL/SpringQL/releases" ]; then
Expand Down