diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c873acc7..1f822207 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,6 +6,11 @@ on: - "master" paths: - 'rockspecs/**' + workflow_dispatch: + inputs: + version: + description: 'Version to publish, e.g. 4.1.6' + required: true permissions: contents: write @@ -31,28 +36,47 @@ jobs: shell: bash env: COMMIT_MESSAGE: ${{ github.event.head_commit.message }} + INPUT_VERSION: ${{ inputs.version }} run: | - title="$COMMIT_MESSAGE" - re="^feat: release v*(\S+)" - if [[ $title =~ $re ]]; then - echo "version=v${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT" - echo "version_without_v=${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT" + if [[ -n "$INPUT_VERSION" ]]; then + version="${INPUT_VERSION#v}" else - echo "commit format is not correct" - exit 1 + title="$COMMIT_MESSAGE" + re="^feat: release v*(\S+)" + if [[ $title =~ $re ]]; then + version="${BASH_REMATCH[1]}" + else + echo "commit format is not correct" + exit 1 + fi fi + echo "version=v${version}" >> "$GITHUB_OUTPUT" + echo "version_without_v=${version}" >> "$GITHUB_OUTPUT" - name: Create Release env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} VERSION: ${{ steps.release_env.outputs.version }} run: | - gh release create "$VERSION" --title "$VERSION" --generate-notes + if gh release view "$VERSION" >/dev/null 2>&1; then + echo "release $VERSION already exists, skipping" + else + gh release create "$VERSION" --title "$VERSION" --generate-notes + fi - name: Upload to luarocks env: LUAROCKS_TOKEN: ${{ secrets.LUAROCKS_TOKEN }} VERSION_WITHOUT_V: ${{ steps.release_env.outputs.version_without_v }} run: | + if [[ -z "$LUAROCKS_TOKEN" ]]; then + echo "LUAROCKS_TOKEN is empty: the org secret is not granted to this repository" + exit 1 + fi + rockspec="rockspecs/lua-resty-session-api7-${VERSION_WITHOUT_V}-0.rockspec" + if [[ ! -f "$rockspec" ]]; then + echo "rockspec not found: $rockspec" + exit 1 + fi luarocks install dkjson - luarocks upload "rockspecs/lua-resty-session-api7-${VERSION_WITHOUT_V}-0.rockspec" --api-key="${LUAROCKS_TOKEN}" + luarocks upload "$rockspec" --api-key="${LUAROCKS_TOKEN}"