forked from gzuidhof/coi-serviceworker
-
Notifications
You must be signed in to change notification settings - Fork 0
78 lines (71 loc) · 2.77 KB
/
main.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
name: check version number and minify
on:
push:
paths:
- 'coi-serviceworker.js'
- 'package.json'
permissions:
contents: write
jobs:
ci:
name: ci
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- name: setup node
uses: actions/setup-node@v3
- name: git config
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git remote set-url origin https://github-actions:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
- name: npm ci
if: ${{ !contains(toJSON(github.event.modified), 'package.json') }}
run: npm ci
- name: npm install
if: ${{ contains(toJSON(github.event.modified), 'package.json') }}
run: npm install
- name: git diff package-lock.json
id: lockdiff
run: echo "::set-output name=modified_files::$(git diff --name-only)"
- name: push package-lock.json
if: ${{ steps.lockdiff.outputs.modified_files == 'package-lock.json' }}
run: |
git add package-lock.json
git commit -m "update package-lock.json"
git push origin HEAD:${GITHUB_REF}
- name: get package_version
run: npx -c 'echo "package_version=$npm_package_version"' >> "${GITHUB_ENV}"
- name: check package_version
run: echo "${package_version}" | grep -x -E '[0-9]+\.[0-9]+\.[0-9]+'
- name: get js_version
run: sed -n -e '1s,^/*! coi-serviceworker v\([0-9]+\.[0-9]+\.[0-9]+\) - .*$,js_version=\1,' coi-serviceworker.js >> "${GITHUB_ENV}"
- name: check js_version
run: echo "${js_version}" | grep -x -E '[0-9]+\.[0-9]+\.[0-9]+'
- name: push coi-serviceworker.js
if: env.package_version != env.js_version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
sed -i -e '1s/ v\([0-9]+\.[0-9]+\.[0-9]+\) / v'"${package_version}"' /' coi-serviceworker.js
git add coi-serviceworker.js
git commit -m "sync version numbers"
git push origin HEAD:${GITHUB_REF}
- name: minify
run: npm run minify
- name: git diff coi-serviceworker.min.js
id: mindiff
run: echo "::set-output name=modified_files::$(git diff --name-only)"
- name: push coi-serviceworker.min.js
if: ${{ steps.mindiff.outputs.modified_files == 'coi-serviceworker.min.js' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git add coi-serviceworker.min.js
git commit -m "minify"
git push origin HEAD:${GITHUB_REF}
- name: git diff
run: git diff --exit-code