Skip to content

Update build.yml

Update build.yml #38

Workflow file for this run

name: Build and Release
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
release:
types: [published]
workflow_dispatch:
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build
run: |
mkdir -p dist
npm run build
# Only for releases: prepare and upload the asset
- name: Handle release
if: github.event_name == 'release'
run: |
# Copy built file to root for easier access
cp dist/ember-mug-card.js ./ember-mug-card.js
# Install GitHub CLI
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh
# Get release tag
TAG_NAME="${GITHUB_REF#refs/tags/}"
# Authenticate with GITHUB_TOKEN
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
# Upload the file to the release
gh release upload "$TAG_NAME" ember-mug-card.js --clobber
# Get changelog content and update release notes
CHANGELOG=$(cat CHANGELOG.md)
gh release edit "$TAG_NAME" --notes "$CHANGELOG"