build(project): scaffold plugin delivery
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up Java
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: 17
|
||||
cache: gradle
|
||||
|
||||
- name: Validate conventional commits
|
||||
if: github.event_name == 'pull_request'
|
||||
run: |
|
||||
npx -y \
|
||||
-p @commitlint/cli \
|
||||
-p @commitlint/config-conventional \
|
||||
commitlint --from "${{ github.event.pull_request.base.sha }}" --to "${{ github.sha }}" \
|
||||
--extends @commitlint/config-conventional
|
||||
|
||||
- name: Build and test
|
||||
run: ./gradlew clean check jar
|
||||
|
||||
- name: Upload development artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: spigot-tyrant-${{ github.sha }}
|
||||
path: build/libs/*.jar
|
||||
if-no-files-found: error
|
||||
@@ -0,0 +1,141 @@
|
||||
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@24.2.9 \
|
||||
-p @semantic-release/commit-analyzer@13.0.1 \
|
||||
-p @semantic-release/release-notes-generator@14.1.0 \
|
||||
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-tyrant-${{ steps.release.outputs.version }}
|
||||
path: build/libs/spigot-tyrant-${{ 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-tyrant-${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-tyrant-${VERSION}.jar"
|
||||
Reference in New Issue
Block a user