Skip to content

Commit

Permalink
ci: fix tag name for alpha release and beta number for beta release (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
wangl-cc authored Nov 29, 2023
1 parent bed3642 commit 37e11cd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
43 changes: 28 additions & 15 deletions .github/scripts/parse_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,67 @@
set -e

CARGO_PKG_VERSION=$(yq -r '.package.version' maa-cli/Cargo.toml)
COMMIT_SHA=$(git rev-parse HEAD)
commit_sha=$(git rev-parse HEAD)

if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then
echo "PR detected, marking version as alpha pre-release and skipping publish"
channel="alpha"
version="$CARGO_PKG_VERSION-alpha.$(date +%s)"
tag="nightly"
publish="false"
VERSION="$CARGO_PKG_VERSION-alpha.$(date +%s)"
elif [ "$GITHUB_EVENT_NAME" == "schedule" ]; then
echo "Scheduled event detected, marking version as alpha pre-release and publish to alpha channel"
# check if there are some new commits
channel="alpha"
pubulished_commit=$(yq -r ".details.commit" version/$channel.json)
last_commit="$COMMIT_SHA"
if [ "$pubulished_commit" == "$last_commit" ]; then
published_commit=$(yq -r ".details.commit" version/$channel.json)
if [ "$published_commit" == "$commit_sha" ]; then
echo "No new commits, exiting, skipping all steps"
echo "skip=true" >> "$GITHUB_OUTPUT"
exit 0
fi
VERSION="$CARGO_PKG_VERSION-alpha.$(date +%s)"
publish="true"
version="$CARGO_PKG_VERSION-alpha.$(date +%s)"
tag="nightly"
elif [ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]; then
echo "Workflow dispatch event detected, reading inputs"
beta=$(yq -r '.inputs.beta' "$GITHUB_EVENT_PATH")
if [ "$beta" == "true" ]; then
echo "Beta flag detected, marking version as beta pre-release and publish to beta channel"
beta_number=$(yq -r ".details.beta_number" version/beta.json)
VERSION="$CARGO_PKG_VERSION-beta.$beta_number"
channel="beta"
published_version=$(yq -r ".details.version" version/beta.json)
published_version_prefix=${published_version%-*}
published_version_suffix=${published_version#*-}
if [ "$published_version_prefix" != "$CARGO_PKG_VERSION" ]; then
echo "Last published version is not the same as current version (published: $published_version)"
version="$CARGO_PKG_VERSION-$channel.1"
elif [ "$published_version_suffix" == "$published_version" ]; then
echo "Last published version is not a pre-release version (published: $published_version)"
version="$CARGO_PKG_VERSION-$channel.1"
else
beta_number=${published_version_suffix#*.}
version="$CARGO_PKG_VERSION-$channel.$((beta_number + 1))"
fi
else
echo "No beta flag detected, marking version as stable release and publish to stable channel"
channel="stable"
fi
publish=$(yq -r '.inputs.publish' "$GITHUB_EVENT_PATH")
else
else # push to a tag
REF_VERSION=${GITHUB_REF#refs/tags/v}
if [ "$REF_VERSION" == "$GITHUB_REF" ]; then
echo "Version tag not matched, aborting"
exit 1
fi
echo "Tag detected, marking version as stable release and publish to stable channel"
channel="stable"
VERSION="$REF_VERSION"
version="$REF_VERSION"
fi
echo "Release version $VERSION to $channel channel and publish=$publish"

echo "Release version $version to $channel channel with tag $tag"
{
echo "commit=$commit_sha"
echo "channel=$channel"
echo "commit=$COMMIT_SHA"
echo "version=$VERSION"
echo "publish=$publish"
echo "version=$version"
echo "tag=${tag:-v$version}"
echo "publish=${publish:-ture}"
echo "skip=false"
} >> "$GITHUB_OUTPUT"
9 changes: 5 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.tag }}
commit: ${{ steps.version.outputs.commit }}
channel: ${{ steps.version.outputs.channel }}
prerelease: ${{ steps.version.outputs.channel != 'stable' }}
Expand Down Expand Up @@ -179,6 +180,7 @@ jobs:
- name: Extract files, Generate checksums and Update version.json
run: |
VERSION=${{ needs.meta.outputs.version }}
TAG=${{ needs.meta.outputs.tag }}
COMMIT=${{ needs.meta.outputs.commit }}
CHANNEL=${{ needs.meta.outputs.channel }}
Expand All @@ -191,7 +193,7 @@ jobs:
# target independent version info
for version_file in "${version_files[@]}"; do
yq -i -oj ".version = \"$VERSION\"" "$version_file"
yq -i -oj ".details.tag = \"v$VERSION\"" "$version_file"
yq -i -oj ".details.tag = \"$TAG\"" "$version_file"
yq -i -oj ".details.commit = \"$COMMIT\"" "$version_file"
done
Expand Down Expand Up @@ -221,7 +223,7 @@ jobs:
# old version info (deprecated)
version_file="version/version.json"
yq -i -oj ".maa-cli.$target.version = \"$VERSION\"" "$version_file"
yq -i -oj ".maa-cli.$target.tag = \"v$VERSION\"" "$version_file"
yq -i -oj ".maa-cli.$target.tag = \"$TAG\"" "$version_file"
yq -i -oj ".maa-cli.$target.name = \"$archive_name\"" "$version_file"
yq -i -oj ".maa-cli.$target.size = $size" $version_file
yq -i -oj ".maa-cli.$target.sha256sum = \"$checksum_hash\"" "$version_file"
Expand All @@ -238,8 +240,7 @@ jobs:
if: ${{ fromJson(needs.meta.outputs.publish) }}
with:
name: v${{ needs.meta.outputs.version }}
# use the same tag for all alpha releases
tag_name: ${{ fromJson(needs.meta.outputs.channel) == 'alpha' && 'alpha' || format('v{0}', needs.meta.outputs.version) }}
tag_name: ${{ needs.meta.outputs.tag }}
prerelease: ${{ fromJson(needs.meta.outputs.prerelease) }}
body: ${{ needs.release-note.outputs.content }}
fail_on_unmatched_files: true
Expand Down

0 comments on commit 37e11cd

Please sign in to comment.