Skip to content

Create Release

Create Release #291

Workflow file for this run

name: Create Release
on:
workflow_dispatch:
inputs:
release_kind:
type: choice
description: The type of release.
default: prerelease
required: true
options:
- prerelease
- start-rc
- stable
publish:
description: "True to publish release to git, vpm. if false, this creates release asset only"
type: boolean
required: false
env:
PKG_NAME: com.anatawa12.avatar-optimizer
SOMETHING_RELEASER_SEMVER: 1
concurrency:
group: publish
cancel-in-progress: true
permissions: write-all
jobs:
create-release:
runs-on: ubuntu-latest
environment:
name: actions-github-app
outputs:
version: ${{ steps.update-version.outputs.version }}
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
submodules: recursive
- uses: anatawa12/something-releaser@v2
- uses: snow-actions/[email protected]
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: '0.111.3'
extended: true
- name: Check release is public
if: github.event.inputs.release_kind == 'stable'
run: |
if [[ "$(jq '.private == true' < package.json)" == "true" ]]; then
echo "package.json is private"
exit 255
fi
- name: Check release is public
run: |
if [[ "$(jq '.["private-beta"] == true' < package.json)" == "true" ]]; then
echo "package.json is private-beta"
exit 255
fi
- name: Update Version Name
id: update-version
run: |
# set version name in properties file
case "$RELEASE_KIND_IN" in
"prerelease" )
set-version "$(version-next "$(get-version)")"
gh-export-variable PRERELEASE true
;;
"start-rc" )
set-version "$(version-set-channel "$(get-version)" rc)"
gh-export-variable PRERELEASE true
;;
"stable" )
set-version "$(version-set-channel "$(get-version)" stable)"
gh-export-variable PRERELEASE false
;;
* )
echo "invalid release kind: $RELEASE_KIND_IN"
exit 255
;;
esac
case "$GITHUB_REF_NAME" in
master | master-* )
echo "head is master or master-*"
;;
* )
echo "invalid release kind: $RELEASE_KIND_IN is not allowd for $GITHUB_REF_NAME"
exit 255
;;
esac
gh-export-variable VERSION "$(get-version)"
gh-set-output version "$(get-version)"
env:
RELEASE_KIND_IN: ${{ github.event.inputs.release_kind }}
# region changelog
- name: Create Changelog
id: changelog
uses: anatawa12/sh-actions/changelog/prepare-release@master
with:
version: ${{ env.VERSION }}
prerelease: ${{ env.PRERELEASE }}
tag-prefix: v
prerelease-note-heading: |
Version ${{ env.VERSION }}
---
Installer unitypackage for this version is [here][installer for this].
[installer for this]: https://api.anatawa12.com/create-vpai/?name=AvatarOptimizer-{}-installer.unitypackage&repo=https://vpm.anatawa12.com/vpm.json&package=com.anatawa12.avatar-optimizer&version=${{ env.VERSION }}
**This is SNAPSHOT, not a stable release. make sure this may have many bugs.**
release-note-heading: |
Version ${{ env.VERSION }}
---
Installer unitypackage for this version is [here][installer for this].
[installer for this]: https://api.anatawa12.com/create-vpai/?name=AvatarOptimizer-{}-installer.unitypackage&repo=https://vpm.anatawa12.com/vpm.json&package=com.anatawa12.avatar-optimizer&version=${{ env.VERSION }}
- name: Upload CHANGELOG.md
if: ${{ !fromJSON(env.PRERELEASE) }}
uses: actions/upload-artifact@v3
with:
name: CHANGELOG
path: CHANGELOG.md
- name: Upload CHANGELOG-PRERELEASE.md
uses: actions/upload-artifact@v3
with:
name: CHANGELOG-PRERELEASE
path: CHANGELOG-PRERELEASE.md
- run: cp "${{ steps.changelog.outputs.release-note }}" release-note.md
- name: Upload release note
uses: actions/upload-artifact@v3
with:
name: changelog
path: release-note.md
- run: rm release-note.md
# endregion changelog
- name: Commit & tag version
if: ${{ inputs.publish }}
run: |
git commit -am "chore: bump version to $VERSION"
git tag "v$VERSION"
# region building
- name: Prepare build folder
run: mkdir build
- name: update changelog url
run: |
STABLE_URL="https://vpm.anatawa12.com/avatar-optimizer/en/docs/changelog/"
BETA_URL="https://vpm.anatawa12.com/avatar-optimizer/beta/en/docs/changelog/"
if $PRERELEASE; then
sed -i'.bak' -e "s|${STABLE_URL}|${BETA_URL}#${VERSION}|" package.json
else
sed -i'.bak' -e "s|${STABLE_URL}|${STABLE_URL}#${VERSION}|" package.json
fi
rm package.json.bak
- name: update csc.rsp
run: |
sed -n '/PUBLISH DELETE MARKER/q;p' -i .csc.rsp.nullunsafe
sed -n '/PUBLISH DELETE MARKER/q;p' -i .csc.rsp.nullsafe
# region vpm release
- name: Build VPM release
run: |
zip -r "build/$PKG_NAME-$VERSION.zip" . -x 'build*' '.*' 'Test~/*'
- name: Upload VPM release
uses: actions/upload-artifact@v3
with:
name: vpm-package
path: build/${{ env.PKG_NAME }}-${{ env.VERSION }}.zip
# endregion vpm release
# region docs
# remember update update-website.yml
- name: Update .docs/config.toml
run: sed -i'.bak' -e "s/(SNAPSHOT)/($VERSION)/" .docs/config.toml && rm .docs/config.toml.bak
- name: Build docs as a beta docs
working-directory: .docs
run: ./build.sh 'https://vpm.anatawa12.com/avatar-optimizer/beta' "$VERSION"
- name: Copy to beta dir if it's release
if: ${{ !fromJSON(env.PRERELEASE) }}
working-directory: .docs
run: mkdir -p static && mv public static/beta
- name: Build docs as a release docs if it's release
if: ${{ !fromJSON(env.PRERELEASE) }}
working-directory: .docs
run: ./build.sh 'https://vpm.anatawa12.com/avatar-optimizer' "$VERSION"
- name: zip docs
run: cd .docs/public && zip ../../build/website.zip -r .
- name: Upload docs
uses: actions/upload-artifact@v3
with:
name: website
path: .docs/public
- name: Restore .docs/config.toml
run: git restore --staged --worktree .docs/config.toml
# endregion docs
# endregion building
- name: Publish Release
if: ${{ inputs.publish }}
run: |
git push && git push origin "v$VERSION"
- name: Publish release to github
if: ${{ inputs.publish }}
env:
GH_TOKEN: ${{ github.token }}
RELEASE_NOTE: ${{ steps.changelog.outputs.release-note }}
shell: bash
run: |
sleep 1
# upload release assets
gh release create "v$VERSION" \
-F "$RELEASE_NOTE" \
${{ fromJSON(env.PRERELEASE) && '--prerelease' || '' }} \
"build/$PKG_NAME-$VERSION.zip" \
build/website.zip \
"package.json" \
- name: Restore package.json
run: git restore --staged --worktree package.json
- name: prepare next release & push
if: inputs.publish && !fromJSON(env.PRERELEASE)
run: |
VERSION="$(version-next "$(get-version)")"
set-version "$(version-set-channel "$VERSION" beta 0)"
git commit -am "chore: prepare for next version: $VERSION"
git push && git push --tags
publish-vpm:
uses: anatawa12/vpm.anatawa12.com/.github/workflows/update-package.yml@master
needs: create-release
if: inputs.publish
with:
version: ${{ needs.create-release.outputs.version }}
environment: vpm.anatawa12.com
website_zip: https://github.com/anatawa12/AvatarOptimizer/releases/download/v${{ needs.create-release.outputs.version }}/website.zip
website_path: ${{ contains(needs.create-release.outputs.version, '-') && 'beta' || '' }}
secrets:
TOKEN: ${{ secrets.VPM_GITHUB_PAT }}