-
Notifications
You must be signed in to change notification settings - Fork 13
140 lines (122 loc) · 4.99 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
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
name: Package and Release
on:
push:
branches:
- master
jobs:
release:
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2 # we need the last two commits to check if the version changed
- name: Get package version
id: check_versions
run: |
$previous_version = git show HEAD~1:release/app/package.json | Select-String -Pattern '"version":' | ForEach-Object { $_ -replace '.*?: "(.*)",', '$1' }
$current_version = git show HEAD:release/app/package.json | Select-String -Pattern '"version":' | ForEach-Object { $_ -replace '.*?: "(.*)",', '$1' }
"previous_version=$previous_version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
"current_version=$current_version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
if ($previous_version -ne $current_version) {
"version_changed=true" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
} else {
"version_changed=false" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
}
"Previous Version = $previous_version" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Append
"Current Version = $current_version" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Append
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: 16
architecture: 'x64'
# GitHub dependencies don't work in GitHub Action workflows...
- name: Remove CascLib dependency
run: npm remove CascLib
- name: Install dependencies
run: npm install
- name: Build package
run: npm run package
- name: Delete release
uses: actions/github-script@v6
with:
script: |
const releaseName = "D2RMM ${{ steps.check_versions.outputs.current_version }}";
const releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo
});
const releaseToDelete = releases.data.find(release => release.name === releaseName);
if (releaseToDelete) {
await github.rest.repos.deleteRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: releaseToDelete.id
});
console.log(`Release ${releaseName} deleted successfully.`);
} else {
console.log(`Release ${releaseName} not found.`);
}
- name: Delete tag
uses: actions/github-script@v6
with:
script: |
const tagName = "v${{ steps.check_versions.outputs.current_version }}";
try {
await github.rest.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `tags/${tagName}`
});
console.log(`Tag ${tagName} deleted successfully.`);
} catch (e) {
if (e.message.includes('Reference does not exist')) {
console.log(`Tag ${tagName} not found.`);
} else {
console.log(`Tag ${tagName} not deleted.`, e);
}
}
- name: Create tag
uses: actions/github-script@v6
with:
script: |
const tagName = "v${{ steps.check_versions.outputs.current_version }}";
try {
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${tagName}`,
sha: context.sha
});
console.log(`Tag ${tagName} created successfully.`);
} catch (e) {
console.log(`Tag ${tagName} not created.`, e);
core.setFailed(e.message);
}
- name: Create release
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
name: D2RMM ${{ steps.check_versions.outputs.current_version }}
tag: v${{ steps.check_versions.outputs.current_version }}
draft: false
prerelease: true
artifacts: release/build/D2RMM ${{ steps.check_versions.outputs.current_version }}.zip
artifactErrorsFailBuild: true
generateReleaseNotes: false
- name: Finalize pre-release
if: steps.check_versions.outputs.version_changed == 'true'
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
name: D2RMM ${{ steps.check_versions.outputs.previous_version }}
tag: v${{ steps.check_versions.outputs.previous_version }}
allowUpdates: true
preRelease: false
- name: Generate documentation
run: npm run docs
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs