142 lines
4.8 KiB
YAML
142 lines
4.8 KiB
YAML
name: Release
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
release:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: write
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
token: ${{ secrets.RELEASE_TOKEN }}
|
|
|
|
- name: Set up Java
|
|
uses: actions/setup-java@v4
|
|
with:
|
|
distribution: temurin
|
|
java-version: 17
|
|
cache: gradle
|
|
|
|
- name: Set up Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 20
|
|
|
|
- name: Build and test before release
|
|
run: ./gradlew clean check
|
|
|
|
- name: Capture previous tag
|
|
id: previous_tag
|
|
run: |
|
|
if git describe --tags --abbrev=0 >/dev/null 2>&1; then
|
|
echo "value=$(git describe --tags --abbrev=0)" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "value=" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
- name: Run semantic-release
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
|
run: |
|
|
npx -y \
|
|
-p semantic-release \
|
|
-p @semantic-release/commit-analyzer \
|
|
-p @semantic-release/release-notes-generator \
|
|
semantic-release \
|
|
--branches main \
|
|
--plugins @semantic-release/commit-analyzer,@semantic-release/release-notes-generator
|
|
|
|
- name: Capture current tag
|
|
id: current_tag
|
|
run: |
|
|
if git describe --tags --exact-match HEAD >/dev/null 2>&1; then
|
|
echo "value=$(git describe --tags --exact-match HEAD)" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "value=" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
- name: Resolve release
|
|
id: release
|
|
env:
|
|
PREVIOUS_TAG: ${{ steps.previous_tag.outputs.value }}
|
|
CURRENT_TAG: ${{ steps.current_tag.outputs.value }}
|
|
run: |
|
|
if [ -n "$CURRENT_TAG" ] && [ "$CURRENT_TAG" != "$PREVIOUS_TAG" ]; then
|
|
echo "created=true" >> "$GITHUB_OUTPUT"
|
|
echo "tag=$CURRENT_TAG" >> "$GITHUB_OUTPUT"
|
|
echo "version=${CURRENT_TAG#v}" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "created=false" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
- name: Build versioned plugin
|
|
if: steps.release.outputs.created == 'true'
|
|
env:
|
|
VERSION: ${{ steps.release.outputs.version }}
|
|
run: ./gradlew clean jar -PreleaseVersion="$VERSION"
|
|
|
|
- name: Upload release workflow artifact
|
|
if: steps.release.outputs.created == 'true'
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: spigot-event-producer-${{ steps.release.outputs.version }}
|
|
path: build/libs/spigot-event-producer-${{ steps.release.outputs.version }}.jar
|
|
if-no-files-found: error
|
|
|
|
- name: Create Gitea release and upload plugin
|
|
if: steps.release.outputs.created == 'true'
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
|
GITEA_SERVER_URL: ${{ github.server_url }}
|
|
REPOSITORY: ${{ github.repository }}
|
|
TAG: ${{ steps.release.outputs.tag }}
|
|
VERSION: ${{ steps.release.outputs.version }}
|
|
PREVIOUS_TAG: ${{ steps.previous_tag.outputs.value }}
|
|
run: |
|
|
api_url="${GITEA_SERVER_URL}/api/v1"
|
|
jar="build/libs/spigot-event-producer-${VERSION}.jar"
|
|
export RELEASE_BODY
|
|
if [ -n "$PREVIOUS_TAG" ]; then
|
|
RELEASE_BODY=$(git log --pretty='format:- %s (%h)' "${PREVIOUS_TAG}..HEAD")
|
|
else
|
|
RELEASE_BODY=$(git log --pretty='format:- %s (%h)' HEAD)
|
|
fi
|
|
payload=$(node -e '
|
|
const payload = {
|
|
tag_name: process.env.TAG,
|
|
name: process.env.TAG,
|
|
body: process.env.RELEASE_BODY,
|
|
draft: false,
|
|
prerelease: false
|
|
};
|
|
process.stdout.write(JSON.stringify(payload));
|
|
')
|
|
response=$(curl --fail-with-body --silent --show-error \
|
|
-X POST \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
"${api_url}/repos/${REPOSITORY}/releases" \
|
|
--data "$payload")
|
|
release_id=$(printf '%s' "$response" | node -e '
|
|
let input = "";
|
|
process.stdin.on("data", chunk => input += chunk);
|
|
process.stdin.on("end", () => {
|
|
const response = JSON.parse(input);
|
|
if (!response.id) process.exit(1);
|
|
process.stdout.write(String(response.id));
|
|
});
|
|
')
|
|
curl --fail-with-body --silent --show-error \
|
|
-X POST \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/octet-stream" \
|
|
--data-binary "@${jar}" \
|
|
"${api_url}/repos/${REPOSITORY}/releases/${release_id}/assets?name=spigot-event-producer-${VERSION}.jar"
|