Skip to content

Commit 22a75e8

Browse files
authored
use plugin-manifest-action for manifest publishing
1 parent b033cbc commit 22a75e8

1 file changed

Lines changed: 30 additions & 62 deletions

File tree

.github/workflows/publish.yaml

Lines changed: 30 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,46 @@
1-
name: generate and publish manifest
1+
name: Generate and Publish Manifest
22

33
on:
44
push:
5-
tags: ["v*"]
5+
tags: [ 'v*' ]
6+
pull_request:
7+
types: [closed]
8+
branches: [main, master]
69

710
permissions:
811
contents: write
912

1013
jobs:
11-
generate-manifest-json:
14+
publish:
1215
runs-on: ubuntu-latest
16+
if: github.event_name == 'push' || (github.event.pull_request.merged == true && startsWith(github.event.pull_request.title, 'Release v'))
1317
steps:
14-
- name: Set repo name
15-
run: |
16-
echo "REPO_NAME=$(echo ${{ github.repository }} | cut -d'/' -f2)" >> $GITHUB_ENV
17-
echo "VERSION=$(echo ${{ github.ref }} | cut -d'/' -f3 | cut -c2-)" >> $GITHUB_ENV
18-
- uses: actions/checkout@v5
19-
- name: Set up Lua
20-
uses: leafo/gh-actions-lua@v12
21-
with:
22-
luaVersion: "5.3.5"
18+
- name: Checkout code
19+
uses: actions/checkout@v4
2320

24-
- name: Install dependencies
21+
- name: Extract version from tag
22+
if: github.event_name == 'push'
2523
run: |
26-
sudo apt-get install luarocks
27-
sudo luarocks install dkjson
24+
VERSION=$(echo ${{ github.ref }} | cut -d'/' -f3 | cut -c2-)
25+
echo "VERSION=$VERSION" >> $GITHUB_ENV
2826
29-
- name: Generate manifest
27+
- name: Extract version from PR title
28+
if: github.event_name == 'pull_request'
3029
run: |
31-
sudo lua -e '
32-
require("metadata");
33-
local dkjson = require("dkjson");
34-
PLUGIN.downloadUrl = "https://github.com/${{ github.repository }}/releases/download/v${{ env.VERSION }}/${{ env.REPO_NAME }}-${{ env.VERSION }}.zip";
35-
local str = dkjson.encode(PLUGIN);
36-
print(str)' > manifest.json
37-
cat manifest.json
38-
- name: Upload JSON file
39-
uses: actions/upload-artifact@v4
40-
with:
41-
name: manifest
42-
path: manifest.json
43-
release-plugin-and-manifest:
44-
needs: generate-manifest-json
45-
runs-on: ubuntu-latest
46-
steps:
47-
- name: Set repo name
30+
PR_TITLE="${{ github.event.pull_request.title }}"
31+
VERSION=$(echo "$PR_TITLE" | grep -oP 'Release v\K[0-9]+\.[0-9]+\.[0-9]+')
32+
echo "VERSION=$VERSION" >> $GITHUB_ENV
33+
34+
- name: Validate version
4835
run: |
49-
echo "REPO_NAME=$(echo ${{ github.repository }} | cut -d'/' -f2)" >> $GITHUB_ENV
50-
echo "VERSION=$(echo ${{ github.ref }} | cut -d'/' -f3 | cut -c2-)" >> $GITHUB_ENV
51-
- name: Checkout code
52-
uses: actions/checkout@v5
53-
- name: Download JSON file
54-
uses: actions/download-artifact@v5
55-
with:
56-
name: manifest
57-
- name: Compress build files
58-
uses: thedoctor0/zip-release@0.7.6
59-
with:
60-
type: "zip"
61-
directory: "./"
62-
filename: "${{ env.REPO_NAME }}-${{ env.VERSION }}.zip"
63-
exclusions: "*.git* manifest.json"
64-
- name: Publish release
65-
uses: svenstaro/upload-release-action@v2
66-
with:
67-
repo_token: ${{ secrets.GITHUB_TOKEN }}
68-
file: ./${{ env.REPO_NAME }}-${{ env.VERSION }}.zip
69-
tag: v${{ env.VERSION }}
70-
file_glob: true
71-
- name: Publish manifest
72-
uses: svenstaro/upload-release-action@v2
36+
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
37+
echo "Invalid version format: $VERSION"
38+
exit 1
39+
fi
40+
echo "Publishing version: $VERSION"
41+
42+
- name: Publish manifest and release
43+
uses: version-fox/plugin-manifest-action@main
7344
with:
74-
repo_token: ${{ secrets.GITHUB_TOKEN }}
75-
file: ./manifest.json
76-
tag: "manifest"
77-
overwrite: true
78-
file_glob: true
45+
version: ${{ env.VERSION }}
46+
github-token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)