Skip to content

Commit cacb243

Browse files
author
shivam
committed
Add release workflow
1 parent d51da4f commit cacb243

File tree

4 files changed

+99
-2745
lines changed

4 files changed

+99
-2745
lines changed

.github/workflows/release.yml

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
on:
2+
push:
3+
# Sequence of patterns matched against refs/tags
4+
tags:
5+
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
6+
7+
name: Upload Release Asset
8+
9+
jobs:
10+
build:
11+
name: Upload Release Asset
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v2
16+
17+
- name: Set tag name
18+
run: echo "TAG_NAME=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
19+
20+
- name: Use deno
21+
uses: denolib/setup-deno@v2
22+
with:
23+
deno-version: v1.x
24+
25+
- name: Use node
26+
uses: actions/setup-node@v1
27+
with:
28+
node-version: 12
29+
30+
- name: Install dev npm packages
31+
run: npm i -g dts-bundle-generator typescript
32+
33+
- name: Generate declaration
34+
run: deno run --allow-write --allow-read --allow-run --unstable declarations.ts ${{ env.TAG_NAME }}
35+
36+
- name: Compile files
37+
run: |
38+
cd temp/
39+
tsc --init
40+
tsc --lib esnext --downlevelIteration --outDir compiled
41+
cd compiled
42+
zip -r ${{ env.TAG_NAME }}.zip .
43+
ls
44+
pwd
45+
46+
- name: Bundle project
47+
run: deno bundle mod.ts bundle.js
48+
49+
50+
- name: Create Release
51+
id: create_release
52+
uses: actions/create-release@v1
53+
env:
54+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
with:
56+
tag_name: ${{ github.ref }}
57+
release_name: Release ${{ github.ref }}
58+
draft: false
59+
prerelease: false
60+
61+
- name: Upload Bundle
62+
uses: actions/upload-release-asset@v1
63+
env:
64+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
with:
66+
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
67+
asset_path: ./bundle.js
68+
asset_name: bundle.js
69+
asset_content_type: text/javascript
70+
71+
- name: Upload declaration file
72+
uses: actions/upload-release-asset@v1
73+
env:
74+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75+
with:
76+
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
77+
asset_path: ./temp/${{ env.TAG_NAME }}.d.ts
78+
asset_name: ${{ env.TAG_NAME }}.d.ts
79+
asset_content_type: text/typescript
80+
81+
- name: Upload zip js bundle
82+
uses: actions/upload-release-asset@v1
83+
env:
84+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85+
with:
86+
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
87+
asset_path: ./temp/compiled/${{ env.TAG_NAME }}.zip
88+
asset_name: ${{ env.TAG_NAME }}.zip
89+
asset_content_type: text/typescript

declarations.ts

+10-29
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import {
66
emptyDirSync,
7-
copySync,
87
} from 'https://deno.land/std/fs/mod.ts'
98

109
const start = Date.now()
@@ -58,33 +57,15 @@ async function generateDeclarations() {
5857
}).status()
5958
}
6059

61-
async function getCurrentTags() {
62-
const process = Deno.run({
63-
cmd: ['git', 'tag', '--points-at', 'HEAD'],
64-
stdout: 'piped',
65-
})
66-
67-
await process.status()
68-
69-
const rawOutput = await process.output()
60+
async function saveBundle() {
61+
const tag = Deno.args[0]
7062

71-
const output = new TextDecoder().decode(rawOutput)
72-
return output.split('\n').filter((a) => !!a)
73-
}
63+
const path = './temp/' + tag + '.d.ts'
7464

75-
async function saveBundle() {
76-
const tags = await getCurrentTags()
77-
78-
tags.forEach((tag) => {
79-
Deno.mkdirSync('./declarations/' + tag, { recursive: true })
80-
const path = './declarations/' + tag + '/mod.d.ts'
81-
copySync('./temp/mod.d.ts', path, { overwrite: true })
82-
83-
let text = Deno.readTextFileSync(path)
84-
text =
85-
"// This file auto-generated. Don't edit this file\n\n" + text
86-
Deno.writeTextFileSync(path, text)
87-
})
65+
let text = Deno.readTextFileSync('./temp/mod.d.ts')
66+
text =
67+
"// This file auto-generated. Don't edit this file\n\n" + text
68+
Deno.writeTextFileSync(path, text)
8869
}
8970

9071
printInfo('copying original files')
@@ -101,9 +82,9 @@ printInfo('saving declarations')
10182
await saveBundle()
10283
printDone('saved declarations')
10384

104-
printInfo('clean up')
105-
emptyDirSync('./temp')
106-
printDone('clean up')
85+
// printInfo('clean up')
86+
// emptyDirSync('./temp')
87+
// printDone('clean up')
10788

10889
// printInfo('refactoring .d.ts files')
10990
// refactorDeclarationsFiles('./temp')

0 commit comments

Comments
 (0)