Skip to content

Commit 6d0535c

Browse files
committed
chore: update github action
1 parent 814f5ad commit 6d0535c

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

.github/workflows/workflow.yaml

+52
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ name: Build Plugin JAR File
33
on:
44
push:
55
branches: [ main ]
6+
release:
7+
types:
8+
- created
69

710
jobs:
811
build:
@@ -43,6 +46,10 @@ jobs:
4346
./gradlew pnpmInstall
4447
- name: Build with Gradle
4548
run: |
49+
# Set the version with tag name when releasing
50+
version=${{ github.event.release.tag_name }}
51+
version=${version#v}
52+
sed -i "s/version=.*-SNAPSHOT$/version=$version/1" gradle.properties
4653
./gradlew clean build -x test
4754
- name: Archive plugin-umami jar
4855
uses: actions/upload-artifact@v2
@@ -51,3 +58,48 @@ jobs:
5158
path: |
5259
build/libs/*-plain.jar
5360
retention-days: 1
61+
62+
github-release:
63+
runs-on: ubuntu-latest
64+
needs: build
65+
if: github.event_name == 'release'
66+
steps:
67+
- name: Download plugin-umami jar
68+
uses: actions/download-artifact@v2
69+
with:
70+
name: plugin-umami
71+
path: build/libs
72+
- name: Get Name of Artifact
73+
id: get_artifact
74+
run: |
75+
ARTIFACT_PATHNAME=$(ls build/libs/*.jar | head -n 1)
76+
ARTIFACT_NAME=$(basename ${ARTIFACT_PATHNAME})
77+
echo "Artifact pathname: ${ARTIFACT_PATHNAME}"
78+
echo "Artifact name: ${ARTIFACT_NAME}"
79+
echo "ARTIFACT_PATHNAME=${ARTIFACT_PATHNAME}" >> $GITHUB_ENV
80+
echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV
81+
echo "RELEASE_ID=${{ github.event.release.id }}" >> $GITHUB_ENV
82+
- name: Upload a Release Asset
83+
uses: actions/github-script@v2
84+
if: github.event_name == 'release'
85+
with:
86+
github-token: ${{secrets.GITHUB_TOKEN}}
87+
script: |
88+
console.log('environment', process.versions);
89+
90+
const fs = require('fs').promises;
91+
92+
const { repo: { owner, repo }, sha } = context;
93+
console.log({ owner, repo, sha });
94+
95+
const releaseId = process.env.RELEASE_ID
96+
const artifactPathName = process.env.ARTIFACT_PATHNAME
97+
const artifactName = process.env.ARTIFACT_NAME
98+
console.log('Releasing', releaseId, artifactPathName, artifactName)
99+
100+
await github.repos.uploadReleaseAsset({
101+
owner, repo,
102+
release_id: releaseId,
103+
name: artifactName,
104+
data: await fs.readFile(artifactPathName)
105+
});

0 commit comments

Comments
 (0)