Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): add ci #57

Merged
merged 18 commits into from
Dec 26, 2023
Merged
80 changes: 80 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Auto Build CI

on:
pull_request:
types: [opened, synchronize, reopened]

permissions:
pull-requests: write
contents: write

env:
EM_VERSION: 3.1.51
EM_CACHE_FOLDER: ".emsdk-cache"

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Get PR number
id: get-pr-number
uses: mgaitan/gha-get-pr-number@main
- name: Build Start Dispatch
uses: peter-evans/repository-dispatch@v2
with:
event-type: build-start
client-payload: '{ "pr-number": ${{ steps.get-pr-number.outputs.number }} }'
- uses: actions/checkout@v4
- name: Setup system libraries cache
id: cache-system-libraries
uses: actions/cache@v2
with:
path: ${{ env.EM_CACHE_FOLDER }}
key: ${{ env.EM_VERSION }}-${{ runner.os }}
- name: Setup emsdk cache
uses: mymindstorm/setup-emsdk@v13
with:
version: ${{ env.EM_VERSION }}
actions-cache-folder: ${{ env.EM_CACHE_FOLDER }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "latest"
cache: "npm"
- name: Get commit ID
id: "commit-id"
run: echo "id=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Patch package.json
run: npm pkg set version=$(git rev-parse --short HEAD)
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build:all
- name: Pack
run: npm pack
- name: Release
id: "release"
uses: ncipollo/release-action@v1
with:
artifacts: "zxing-wasm-${{ steps.commit-id.outputs.id }}.tgz"
commit: ${{ github.head_ref || github.ref_name }}
tag: "pr-${{ steps.get-pr-number.outputs.number }}-test-package"
allowUpdates: true
- name: Get release url
id: release-url
uses: frabert/replace-string-action@v2
with:
pattern: "^(.+?/releases/)tag(/.+?)$"
string: ${{ steps.release.outputs.html_url }}
replace-with: "$1download$2/zxing-wasm-${{ steps.commit-id.outputs.id }}.tgz"
- name: Build Finish Dispatch
uses: peter-evans/repository-dispatch@v2
with:
event-type: build-finish
client-payload: '{ "release-url": "${{ steps.release-url.outputs.replaced }}", "pr-number": ${{ steps.get-pr-number.outputs.number }} }'
- name: Clean up
if: failure()
uses: peter-evans/repository-dispatch@v2
with:
event-type: build-fail
client-payload: '{ "pr-number": ${{ steps.get-pr-number.outputs.number }} }'
22 changes: 22 additions & 0 deletions .github/workflows/delete-ci-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Delete CI Releases

on:
pull_request:
types: [closed]

permissions:
pull-requests: write
contents: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Get PR number
id: get-pr-number
uses: mgaitan/gha-get-pr-number@main
- name: Delete CI releases
uses: dev-drprasad/[email protected]
with:
keep_latest: 0
delete_tag_pattern: pr-${{ steps.get-pr-number.outputs.number }}-test-package
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ docs
build
coverage
src/**/zxing_*.wasm
src/**/zxing_*.js
src/**/zxing_*.js

.emsdk-cache
Loading