generated from KevinBatdorf/alpine-plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 19
90 lines (88 loc) · 3.28 KB
/
publish-to-npm.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
name: Publish to npm
on:
release:
types: [published]
jobs:
publish:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup Node (${{ matrix.node-version }})
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
registry-url: https://registry.npmjs.org/
- name: Set up git user
run: git config --global user.name ${GITHUB_ACTOR}
- name: Set up git email
run: git config --global user.name ${GITHUB_ACTOR}@users.noreply.github.com
- name: Install dependencies
run: npm ci
- name: Disable branch protection on master
uses: octokit/[email protected]
with:
route: PUT /repos/:repository/branches/master/protection
repository: ${{ github.repository }}
enforce_admins: |
null
required_status_checks: |
null
required_pull_request_reviews: |
null
restrictions: |
null
env:
GITHUB_TOKEN: ${{ secrets.GH_ADMIN_TOKEN }}
- name: Build dist folder
run: npm run build
- name: Commit dist folder if needed #it fails if nothing has changed so we allow an error
run: git commit -am 'Rebuild dist'
continue-on-error: true
- name: Read tag name
run: echo "RELEASE_VERSION=${GITHUB_REF:10}" >> $GITHUB_ENV
- name: Delete tag #for some reason npm version fails if the tag exists
run: git tag -d $RELEASE_VERSION
- name: Update version in package.json
run: npm version $RELEASE_VERSION
- name: Generate version for cdn links
run: echo "CDN_VERSION=$(echo $RELEASE_VERSION | sed 's/v\([0-9]\)\.\([0-9]\)\.[0-9]/\1.\2.x/g')" >> $GITHUB_ENV
- name: Update README
run: sed -i "s/[0-9]\.[0-9]\.x/$CDN_VERSION/g" README.md
- name: Commit README if needed #it fails if nothing has changed so we allow an error
run: git commit -am 'Update version in README'
continue-on-error: true
- name: Update CHANGELOG
run: sed -i "/\[Unreleased\]/a\\\n## [${RELEASE_VERSION}] - $(date +"%Y-%m-%d")" CHANGELOG.md
- name: Commit CHANGELOG
run: git commit -am 'Update version in README'
- name: Push changed files to master
run: git push origin HEAD:master
- name: Recreate tag
run: git tag -f $RELEASE_VERSION
- name: Update remote tag
run: git push --tags --force
- name: Re-eanable branch protection on master
uses: octokit/[email protected]
with:
route: PUT /repos/:repository/branches/master/protection
repository: ${{ github.repository }}
enforce_admins: |
true
required_status_checks: |
strict: true
contexts:
- build (12.x)
required_pull_request_reviews: |
null
restrictions: |
null
env:
GITHUB_TOKEN: ${{ secrets.GH_ADMIN_TOKEN }}
- name: Publish to npm
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}