ci(自动化): 自动打包 #15
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Plugin JAR File | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- "**" | |
- "!**.md" | |
release: | |
types: | |
- created | |
pull_request: | |
branches: | |
- main | |
paths: | |
- "**" | |
- "!**.md" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
submodules: true | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'temurin' | |
cache: 'gradle' | |
java-version: 17 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
- uses: pnpm/action-setup@v2.0.1 | |
name: Install pnpm | |
id: pnpm-install | |
with: | |
version: 8 | |
run_install: false | |
- name: Get pnpm store directory | |
id: pnpm-cache | |
run: | | |
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_ENV | |
- uses: actions/cache@v3 | |
name: Setup pnpm cache | |
with: | |
path: ${{ env.pnpm_cache_dir }} | |
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/widget/pnpm-lock.yaml') }} | |
restore-keys: | | |
${{ runner.os }}-pnpm-store- | |
- name: Install Frontend Dependencies | |
run: | | |
./gradlew pnpmInstall | |
- name: Build with Gradle | |
run: | | |
# Set the version with tag name when releasing | |
version=${{ github.event.release.tag_name }} | |
version=${version#v} | |
sed -i "s/version=.*-SNAPSHOT$/version=$version/1" gradle.properties | |
./gradlew clean build -x test | |
- name: Archive plugin-picture-bed jar | |
uses: actions/upload-artifact@v2 | |
with: | |
name: plugin-picture-bed | |
path: | | |
build/libs/*.jar | |
retention-days: 1 | |
github-release: | |
runs-on: ubuntu-latest | |
needs: build | |
if: github.event_name == 'release' | |
steps: | |
- name: Download plugin-picture-bed jar | |
uses: actions/download-artifact@v2 | |
with: | |
name: plugin-picture-bed | |
path: build/libs | |
- name: Get Name of Artifact | |
id: get_artifact | |
run: | | |
ARTIFACT_PATHNAME=$(ls build/libs/*.jar | head -n 1) | |
ARTIFACT_NAME=$(basename ${ARTIFACT_PATHNAME}) | |
echo "Artifact pathname: ${ARTIFACT_PATHNAME}" | |
echo "Artifact name: ${ARTIFACT_NAME}" | |
echo "ARTIFACT_PATHNAME=${ARTIFACT_PATHNAME}" >> $GITHUB_ENV | |
echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV | |
echo "RELEASE_ID=${{ github.event.release.id }}" >> $GITHUB_ENV | |
- name: Upload a Release Asset | |
uses: actions/github-script@v2 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const fs = require('fs').promises; | |
const { repo: { owner, repo }, sha } = context; | |
const releaseId = process.env.RELEASE_ID; | |
const artifactPathName = process.env.ARTIFACT_PATHNAME; | |
const artifactName = process.env.ARTIFACT_NAME; | |
await github.repos.uploadReleaseAsset({ | |
owner, repo, | |
release_id: releaseId, | |
name: artifactName, | |
data: await fs.readFile(artifactPathName) | |
}); |