Skip to content

Commit

Permalink
Add release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
shivam committed Jan 29, 2021
1 parent d51da4f commit cacb243
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 2,745 deletions.
89 changes: 89 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

name: Upload Release Asset

jobs:
build:
name: Upload Release Asset
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set tag name
run: echo "TAG_NAME=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Use deno
uses: denolib/setup-deno@v2
with:
deno-version: v1.x

- name: Use node
uses: actions/setup-node@v1
with:
node-version: 12

- name: Install dev npm packages
run: npm i -g dts-bundle-generator typescript

- name: Generate declaration
run: deno run --allow-write --allow-read --allow-run --unstable declarations.ts ${{ env.TAG_NAME }}

- name: Compile files
run: |
cd temp/
tsc --init
tsc --lib esnext --downlevelIteration --outDir compiled
cd compiled
zip -r ${{ env.TAG_NAME }}.zip .
ls
pwd
- name: Bundle project
run: deno bundle mod.ts bundle.js


- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false

- name: Upload Bundle
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
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
asset_path: ./bundle.js
asset_name: bundle.js
asset_content_type: text/javascript

- name: Upload declaration file
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
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
asset_path: ./temp/${{ env.TAG_NAME }}.d.ts
asset_name: ${{ env.TAG_NAME }}.d.ts
asset_content_type: text/typescript

- name: Upload zip js bundle
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
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
asset_path: ./temp/compiled/${{ env.TAG_NAME }}.zip
asset_name: ${{ env.TAG_NAME }}.zip
asset_content_type: text/typescript
39 changes: 10 additions & 29 deletions declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import {
emptyDirSync,
copySync,
} from 'https://deno.land/std/fs/mod.ts'

const start = Date.now()
Expand Down Expand Up @@ -58,33 +57,15 @@ async function generateDeclarations() {
}).status()
}

async function getCurrentTags() {
const process = Deno.run({
cmd: ['git', 'tag', '--points-at', 'HEAD'],
stdout: 'piped',
})

await process.status()

const rawOutput = await process.output()
async function saveBundle() {
const tag = Deno.args[0]

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

async function saveBundle() {
const tags = await getCurrentTags()

tags.forEach((tag) => {
Deno.mkdirSync('./declarations/' + tag, { recursive: true })
const path = './declarations/' + tag + '/mod.d.ts'
copySync('./temp/mod.d.ts', path, { overwrite: true })

let text = Deno.readTextFileSync(path)
text =
"// This file auto-generated. Don't edit this file\n\n" + text
Deno.writeTextFileSync(path, text)
})
let text = Deno.readTextFileSync('./temp/mod.d.ts')
text =
"// This file auto-generated. Don't edit this file\n\n" + text
Deno.writeTextFileSync(path, text)
}

printInfo('copying original files')
Expand All @@ -101,9 +82,9 @@ printInfo('saving declarations')
await saveBundle()
printDone('saved declarations')

printInfo('clean up')
emptyDirSync('./temp')
printDone('clean up')
// printInfo('clean up')
// emptyDirSync('./temp')
// printDone('clean up')

// printInfo('refactoring .d.ts files')
// refactorDeclarationsFiles('./temp')
Expand Down
Loading

0 comments on commit cacb243

Please sign in to comment.