forked from danhper/atomic-chrome
-
Notifications
You must be signed in to change notification settings - Fork 1
141 lines (134 loc) · 5.24 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
name: Build, Release, and Publish Chrome Extension
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:
DIRECTORY: app
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' $DIRECTORY/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' $DIRECTORY/manifest.json > temp.json && mv temp.json $DIRECTORY/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 $DIRECTORY/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 $DIRECTORY/manifest.json
git commit -m "Increment version to $NEW_VERSION"
git push
fi
- name: Build the project
run: npm run build
- name: Zip the app directory for release
run: |
cd ${{ env.DIRECTORY }}
ZIP_NAME="release-${{ env.NEW_VERSION }}.zip"
zip -r "../${ZIP_NAME}" ./*
echo "ZIPPED_FILE=${ZIP_NAME}" >> $GITHUB_ENV
cd ..
- name: Upload zipped app as artifact
uses: actions/upload-artifact@v4
with:
name: release-zip-${{ env.NEW_VERSION }}
path: ${{ github.workspace }}/${{ env.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 zipped app artifact
uses: actions/download-artifact@v4
with:
name: release-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: "release-${{ needs.PrepareBuildAndZip.outputs.NEW_VERSION }}.zip"
token: ${{ secrets.GITHUB_TOKEN }}