From 6d0535cdd38b55f59e7666196ce83fbf59c1027c Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Wed, 26 Oct 2022 17:03:10 +0800 Subject: [PATCH] chore: update github action --- .github/workflows/workflow.yaml | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index e13781a..b5c4175 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -3,6 +3,9 @@ name: Build Plugin JAR File on: push: branches: [ main ] + release: + types: + - created jobs: build: @@ -43,6 +46,10 @@ jobs: ./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-umami jar uses: actions/upload-artifact@v2 @@ -51,3 +58,48 @@ jobs: path: | build/libs/*-plain.jar retention-days: 1 + + github-release: + runs-on: ubuntu-latest + needs: build + if: github.event_name == 'release' + steps: + - name: Download plugin-umami jar + uses: actions/download-artifact@v2 + with: + name: plugin-umami + 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 + if: github.event_name == 'release' + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + console.log('environment', process.versions); + + const fs = require('fs').promises; + + const { repo: { owner, repo }, sha } = context; + console.log({ owner, repo, sha }); + + const releaseId = process.env.RELEASE_ID + const artifactPathName = process.env.ARTIFACT_PATHNAME + const artifactName = process.env.ARTIFACT_NAME + console.log('Releasing', releaseId, artifactPathName, artifactName) + + await github.repos.uploadReleaseAsset({ + owner, repo, + release_id: releaseId, + name: artifactName, + data: await fs.readFile(artifactPathName) + }); \ No newline at end of file