|
1 | 1 | name: Create Release
|
| 2 | +permissions: |
| 3 | + contents: write |
2 | 4 |
|
3 | 5 | on:
|
4 | 6 | push:
|
5 | 7 | branches:
|
6 |
| - - master |
| 8 | + - main |
| 9 | + - master |
7 | 10 |
|
8 | 11 | jobs:
|
9 | 12 | release:
|
10 | 13 | runs-on: ubuntu-latest
|
11 | 14 |
|
12 | 15 | steps:
|
13 |
| - - name: Checkout repository |
14 |
| - uses: actions/checkout@v2 |
15 |
| - |
16 |
| - - name: Set up Node.js |
17 |
| - uses: actions/setup-node@v2 |
18 |
| - with: |
19 |
| - node-version: '20' |
20 |
| - |
21 |
| - - name: Install dependencies |
22 |
| - run: npm install |
23 |
| - |
24 |
| - - name: Build the plugin |
25 |
| - run: npm run build |
26 |
| - |
27 |
| - - name: Extract version from manifest.json |
28 |
| - id: get_version |
29 |
| - run: | |
30 |
| - version=$(jq -r '.version' manifest.json) |
31 |
| - echo "Version found: $version" |
32 |
| - echo "##[set-output name=version;]$version" |
33 |
| -
|
34 |
| - - name: Create GitHub Release |
35 |
| - id: create_release |
36 |
| - uses: actions/create-release@v1 |
37 |
| - env: |
38 |
| - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
39 |
| - with: |
40 |
| - tag_name: ${{ steps.get_version.outputs.version }} |
41 |
| - release_name: Release ${{ steps.get_version.outputs.version }} |
42 |
| - draft: false |
43 |
| - prerelease: false |
44 |
| - |
45 |
| - - name: Upload Release Assets |
46 |
| - uses: actions/upload-release-asset@v1 |
47 |
| - env: |
48 |
| - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
49 |
| - with: |
50 |
| - upload_url: ${{ steps.create_release.outputs.upload_url }} |
51 |
| - asset_path: ./main.js |
52 |
| - asset_name: main.js |
53 |
| - asset_content_type: application/javascript |
54 |
| - |
55 |
| - - name: Upload manifest.json |
56 |
| - uses: actions/upload-release-asset@v1 |
57 |
| - env: |
58 |
| - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
59 |
| - with: |
60 |
| - upload_url: ${{ steps.create_release.outputs.upload_url }} |
61 |
| - asset_path: ./manifest.json |
62 |
| - asset_name: manifest.json |
63 |
| - asset_content_type: application/json |
| 16 | + - name: Checkout repository |
| 17 | + uses: actions/checkout@v2 |
| 18 | + |
| 19 | + - name: Set up Node.js |
| 20 | + uses: actions/setup-node@v2 |
| 21 | + with: |
| 22 | + node-version: "20" |
| 23 | + |
| 24 | + - name: Install dependencies |
| 25 | + if: ${{ hashFiles('package.json') != '' }} |
| 26 | + run: npm install |
| 27 | + |
| 28 | + - name: Build the plugin |
| 29 | + if: ${{ hashFiles('package.json') != '' }} |
| 30 | + run: npm run build |
| 31 | + |
| 32 | + - name: Extract version from manifest.json |
| 33 | + id: get_version |
| 34 | + run: | |
| 35 | + version=$(jq -r '.version' manifest.json) |
| 36 | + echo "Version found: $version" |
| 37 | + echo "manifest_version=$version" >> $GITHUB_ENV |
| 38 | +
|
| 39 | + - name: Check if version exists |
| 40 | + id: check_version |
| 41 | + uses: actions/github-script@v7 |
| 42 | + with: |
| 43 | + script: | |
| 44 | + console.log("Checking version: " + process.env.manifest_version); |
| 45 | + try { |
| 46 | + const { data: releases } = await github.rest.repos.getReleaseByTag({ |
| 47 | + owner: context.repo.owner, |
| 48 | + repo: context.repo.repo, |
| 49 | + tag: process.env.manifest_version |
| 50 | + }); |
| 51 | + const exists = releases.tag_name === process.env.manifest_version; |
| 52 | + console.log(`Version exists: ${exists}`); |
| 53 | + core.setOutput("version_exists", exists); |
| 54 | + } catch (error) { |
| 55 | + if (error.status === 404) { |
| 56 | + console.log('Release does not exist.'); |
| 57 | + core.setOutput("version_exists", false); |
| 58 | + } else { |
| 59 | + throw error; |
| 60 | + } |
| 61 | + } |
| 62 | +
|
| 63 | + - name: Bump version if exists |
| 64 | + if: ${{ steps.check_version.outputs.version_exists == 'true' }} |
| 65 | + run: | |
| 66 | + version=$(jq -r '.version' manifest.json) |
| 67 | + IFS='.' read -ra parts <<< "$version" |
| 68 | + parts[-1]=$((parts[-1] + 1)) |
| 69 | + new_version="${parts[*]}" |
| 70 | + new_version=${new_version// /.} |
| 71 | + echo "New version: $new_version" |
| 72 | + jq ".version = \"$new_version\"" manifest.json > tmp_manifest.json |
| 73 | + mv tmp_manifest.json manifest.json |
| 74 | + git config user.name "github-actions" |
| 75 | + git config user.email "[email protected]" |
| 76 | + git add manifest.json |
| 77 | + git commit -m "Bump version to $new_version" |
| 78 | + git push |
| 79 | + echo "manifest_version=$new_version" >> $GITHUB_ENV |
| 80 | +
|
| 81 | + echo -e "\e[32mVersion bumped to $new_version\e[0m" |
| 82 | + echo -e "\e[32mRelease will be created in new workflow\e[0m" |
| 83 | +
|
| 84 | + - name: Create GitHub Release |
| 85 | + id: create_release |
| 86 | + uses: actions/create-release@v1 |
| 87 | + env: |
| 88 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 89 | + with: |
| 90 | + tag_name: ${{ env.manifest_version }} |
| 91 | + release_name: Release ${{ env.manifest_version }} |
| 92 | + draft: false |
| 93 | + prerelease: false |
| 94 | + |
| 95 | + - name: Upload Release Assets |
| 96 | + uses: actions/upload-release-asset@v1 |
| 97 | + env: |
| 98 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 99 | + with: |
| 100 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 101 | + asset_path: ./main.js |
| 102 | + asset_name: main.js |
| 103 | + asset_content_type: application/javascript |
| 104 | + |
| 105 | + - name: Upload manifest.json |
| 106 | + uses: actions/upload-release-asset@v1 |
| 107 | + env: |
| 108 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 109 | + with: |
| 110 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 111 | + asset_path: ./manifest.json |
| 112 | + asset_name: manifest.json |
| 113 | + asset_content_type: application/json |
0 commit comments