-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (95 loc) · 3.77 KB
/
publish.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
name: Publish npm package
on: push
env:
NPM_TOKEN: ${{secrets.GH_PRIVATE_NPM_TOKEN}}
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: "Checkout source code"
uses: actions/checkout@v3
- name: "Setup node"
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: "Check build"
run: npm install
bump-version:
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: "Checkout source code"
uses: actions/checkout@v3
with:
submodules: "recursive"
- name: "Initialize and Update Submodules"
run: |
echo "Pulling latest submodules changes"
git config --global user.name 'Git bot'
git config --global user.email '[email protected]'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
git submodule foreach 'git config pull.rebase false; git pull --allow-unrelated-histories origin main'
- name: "cat package.json (before bump)"
run: cat ./package.json
- name: "Automated Version Bump"
id: version-bump
uses: "phips28/gh-action-bump-version@master"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "cat package.json (after bump)"
run: cat ./package.json
- name: "Output New Version"
env:
NEW_TAG: ${{ steps.version-bump.outputs.newTag }}
run: echo "new tag $NEW_TAG"
- name: "Upload modified files"
uses: actions/upload-artifact@v3
with:
name: modified-files
path: |
./package.json
./package-lock.json
./templates/starter/**
publish-gpr:
needs: bump-version
runs-on: ubuntu-latest
steps:
- name: "Checkout source code"
uses: actions/checkout@v3
# Clone the repository to a temporary directory
- name: "Clone repository to temp directory"
run: git clone ${{ github.event.repository.clone_url }} temp-repo
# Initialize and update submodules
- name: "Initialize submodules"
run: |
cd temp-repo
git submodule update --init --recursive
- name: "Rename .gitignore for npm inclusion"
run: |
cd temp-repo/templates/starter
mv .gitignore .gitignore_include
- name: "Download modified files"
uses: actions/download-artifact@v3
with:
name: modified-files
- name: "Setup node"
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: "Install can-npm-publish"
run: |
cd temp-repo
npm install can-npm-publish --save-dev
- name: Setup .temp-npmrc file to authenticate with npm
run: |
cd temp-repo
echo "//registry.npmjs.org/:_authToken=${{ env.NPM_TOKEN }}" > .temp-npmrc
- name: "Git status check"
run: |
cd temp-repo
git status
- name: "Publish package if needed"
run: |
cd temp-repo
npx can-npm-publish --verbose && npm publish --no-git-checks --userconfig .temp-npmrc || echo "Does not publish"