|
1 | | -name: generate and publish manifest |
| 1 | +name: Generate and Publish Manifest |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | | - tags: ["v*"] |
| 5 | + tags: [ 'v*' ] |
| 6 | + pull_request: |
| 7 | + types: [closed] |
| 8 | + branches: [main, master] |
6 | 9 |
|
7 | 10 | permissions: |
8 | 11 | contents: write |
9 | 12 |
|
10 | 13 | jobs: |
11 | | - generate-manifest-json: |
| 14 | + publish: |
12 | 15 | runs-on: ubuntu-latest |
| 16 | + if: github.event_name == 'push' || (github.event.pull_request.merged == true && startsWith(github.event.pull_request.title, 'Release v')) |
13 | 17 | 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 |
23 | 20 |
|
24 | | - - name: Install dependencies |
| 21 | + - name: Extract version from tag |
| 22 | + if: github.event_name == 'push' |
25 | 23 | 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 |
28 | 26 |
|
29 | | - - name: Generate manifest |
| 27 | + - name: Extract version from PR title |
| 28 | + if: github.event_name == 'pull_request' |
30 | 29 | 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 |
48 | 35 | 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 |
73 | 44 | 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