forked from danhper/atomic-chrome
-
Notifications
You must be signed in to change notification settings - Fork 1
184 lines (175 loc) · 7.34 KB
/
deploy-extension.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
name: Build, Release, and Publish Chrome and Firefox Extensions
on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
tags:
description: 'Test scenario tags'
versionType:
description: 'Version Increment Type (major, minor, patch) - Leave empty for auto detection based on commit message'
required: false
default: ''
newVersion:
description: 'New Version (e.g., 1.2.3) - Overrides versionType if set'
required: false
default: ''
push:
branches:
- main
env:
PROJECT_NAME: chrome-emacs
jobs:
RunTests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Install dependencies
run: npm ci
- name: Run Test Suite
run: npm run test
PrepareBuildAndZip:
needs: [RunTests]
runs-on: ubuntu-latest
outputs:
NEW_VERSION: ${{ steps.update-version.outputs.NEW_VERSION }}
OLD_VERSION: ${{ steps.update-version.outputs.OLD_VERSION }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Install dependencies
run: npm ci
- name: Update manifest version
id: update-version
run: |
VERSION_FILE=version.env
CURRENT_VERSION=$(jq -r '.version' chrome/manifest.json)
echo "OLD_VERSION=$CURRENT_VERSION" >> $GITHUB_OUTPUT
MANUAL_VERSION_TYPE="${{ github.event.inputs.versionType }}"
MANUAL_NEW_VERSION="${{ github.event.inputs.newVersion }}"
if [[ -n "$MANUAL_NEW_VERSION" ]]; then
NEW_VERSION="$MANUAL_NEW_VERSION"
else
IFS='.' read -ra VERSION <<< "$CURRENT_VERSION"
if [[ "$MANUAL_VERSION_TYPE" == "major" || "${{ github.event.head_commit.message }}" =~ ^major: ]]; then
VERSION[0]=$((VERSION[0]+1))
VERSION[1]=0
VERSION[2]=0
elif [[ "$MANUAL_VERSION_TYPE" == "minor" || "${{ github.event.head_commit.message }}" =~ ^minor: ]]; then
VERSION[1]=$((VERSION[1]+1))
VERSION[2]=0
elif [[ "$MANUAL_VERSION_TYPE" == "patch" || "${{ github.event.head_commit.message }}" =~ ^patch: ]]; then
VERSION[2]=$((VERSION[2]+1))
else
echo "No version increment specified, skipping."
NEW_VERSION="$CURRENT_VERSION"
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
echo "NEW_VERSION=$NEW_VERSION" >> $VERSION_FILE
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_OUTPUT
exit 0
fi
NEW_VERSION="${VERSION[0]}.${VERSION[1]}.${VERSION[2]}"
fi
echo "New version: $NEW_VERSION"
jq --arg v "$NEW_VERSION" '.version = $v' chrome/manifest.json > temp.json && mv temp.json chrome/manifest.json
jq --arg v "$NEW_VERSION" '.version = $v' firefox/manifest.json > temp.json && mv temp.json firefox/manifest.json
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
echo "NEW_VERSION=$NEW_VERSION" >> $VERSION_FILE
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_OUTPUT
# Check if there are any changes
if git diff --quiet --exit-code chrome/manifest.json && git diff --quiet --exit-code firefox/manifest.json; then
echo "No changes in manifest.json. Skipping commit and push."
else
# If there are changes, configure git, commit, and push
git config user.name "github-actions"
git config user.email "[email protected]"
git add chrome/manifest.json firefox/manifest.json
git commit -m "Increment version to $NEW_VERSION"
git push
fi
- name: Build the project
run: npm run build
- name: Zip the Chrome app directory for release
run: |
cd chrome
ZIP_NAME="chrome-release-${{ steps.update-version.outputs.NEW_VERSION }}.zip"
zip -r "../${ZIP_NAME}" ./*
echo "CHROME_ZIPPED_FILE=${ZIP_NAME}" >> $GITHUB_ENV
cd ..
- name: Zip the Firefox app directory for release
run: |
cd firefox
ZIP_NAME="firefox-release-${{ steps.update-version.outputs.NEW_VERSION }}.zip"
zip -r "../${ZIP_NAME}" ./*
echo "FIREFOX_ZIPPED_FILE=${ZIP_NAME}" >> $GITHUB_ENV
cd ..
- name: Zip the source code for submission
run: |
SOURCE_ZIP_NAME="source-code-${{ steps.update-version.outputs.NEW_VERSION }}.zip"
zip -r "${SOURCE_ZIP_NAME}" . \
-x ".git/*" \
-x ".github/*" \
-x "node_modules/*" \
-x "*.zip" \
-x "chrome/scripts/*" \
-x "firefox/scripts/*" \
-x "chrome/images/*" \
-x "firefox/images/*"
echo "SOURCE_ZIPPED_FILE=${SOURCE_ZIP_NAME}" >> $GITHUB_ENV
- name: Upload Chrome zipped app as artifact
uses: actions/upload-artifact@v4
with:
name: chrome-release-zip-${{ steps.update-version.outputs.NEW_VERSION }}
path: ${{ github.workspace }}/${{ env.CHROME_ZIPPED_FILE }}
- name: Upload Firefox zipped app as artifact
uses: actions/upload-artifact@v4
with:
name: firefox-release-zip-${{ steps.update-version.outputs.NEW_VERSION }}
path: ${{ github.workspace }}/${{ env.FIREFOX_ZIPPED_FILE }}
- name: Upload source code zip as artifact
uses: actions/upload-artifact@v4
with:
name: source-code-zip-${{ steps.update-version.outputs.NEW_VERSION }}
path: ${{ github.workspace }}/${{ env.SOURCE_ZIPPED_FILE }}
CreateAndUploadRelease:
needs: [PrepareBuildAndZip]
runs-on: ubuntu-latest
if: ${{ needs.PrepareBuildAndZip.outputs.NEW_VERSION != needs.PrepareBuildAndZip.outputs.OLD_VERSION || github.event_name == 'workflow_dispatch' }}
steps:
- name: Download Chrome zipped app artifact
uses: actions/download-artifact@v4
with:
name: chrome-release-zip-${{ needs.PrepareBuildAndZip.outputs.NEW_VERSION }}
- name: Download Firefox zipped app artifact
uses: actions/download-artifact@v4
with:
name: firefox-release-zip-${{ needs.PrepareBuildAndZip.outputs.NEW_VERSION }}
- name: Download source code zip artifact
uses: actions/download-artifact@v4
with:
name: source-code-zip-${{ needs.PrepareBuildAndZip.outputs.NEW_VERSION }}
- name: Create or Update Release
id: create-release
uses: ncipollo/release-action@v1
with:
allowUpdates: true
tag: ${{ needs.PrepareBuildAndZip.outputs.NEW_VERSION }}
name: Release ${{ needs.PrepareBuildAndZip.outputs.NEW_VERSION }}
draft: false
prerelease: false
artifacts: |
chrome-release-${{ needs.PrepareBuildAndZip.outputs.NEW_VERSION }}.zip
firefox-release-${{ needs.PrepareBuildAndZip.outputs.NEW_VERSION }}.zip
source-code-${{ needs.PrepareBuildAndZip.outputs.NEW_VERSION }}.zip
token: ${{ secrets.GITHUB_TOKEN }}