Build Release #329
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Release | |
on: | |
push: | |
branches: [ "main" ] | |
paths: | |
- 'package.json' | |
# Ignore changes in folders that are affected by the auto commit. (Node.js project) | |
#paths-ignore: | |
# - 'dist/**' | |
pull_request: | |
branches: [ "main" ] | |
workflow_dispatch: | |
inputs: | |
branch: | |
description: 'Branch to build' | |
required: true | |
default: 'main' | |
jobs: | |
build: | |
name: Build for Release | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
#node-version: [18.x, 20.x, 22.x] | |
node-version: [20.x] | |
permissions: | |
contents: write | |
outputs: | |
version: ${{ steps.get_version.outputs.version }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.inputs.branch || github.ref }} | |
- name: Get version from package.json | |
id: get_version | |
run: | | |
VERSION=$(jq -r '.version' package.json) | |
echo "version=$VERSION" >> $GITHUB_OUTPUT | |
- name: Check if tag exists already | |
uses: mukunku/tag-exists-action@v1.4.0 | |
id: check_tag | |
with: | |
tag: "v${{ steps.get_version.outputs.version }}" | |
- name: Cancel if tag is already present | |
run: | | |
echo "Tag already present: v${{ steps.get_version.outputs.version }}. Not creating a new release" | |
gh run cancel ${{ github.run_id }} | |
gh run watch ${{ github.run_id }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
if: steps.check_tag.outputs.exists == 'true' | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: Build | |
run: | | |
npm install | |
npx webpack | |
- name: Create full yaml with version and manage_config as cb-lcars-lovelace.yaml | |
run: | | |
mkdir -p ./dist | |
./create_full_yaml.sh --output ./dist/cb-lcars-lovelace.yaml --path ./src/cb-lcars | |
echo "cb-lcars:" > ./dist/temp.yaml | |
echo " version: ${{ steps.get_version.outputs.version }}" >> ./dist/temp.yaml | |
echo " manage_config: true" >> ./dist/temp.yaml | |
cat ./dist/cb-lcars-lovelace.yaml >> ./dist/temp.yaml | |
mv -f ./dist/temp.yaml ./dist/cb-lcars-lovelace.yaml | |
echo "Head of generated cb-lcars-lovelace.yaml" | |
head -10 ./dist/cb-lcars-lovelace.yaml | |
echo "Copy yamls from src to dist for lint" | |
cp -v ./src/*.yaml ./dist | |
- name: Lint YAML files | |
uses: ibiqlik/action-yamllint@v3.1.1 | |
with: | |
file_or_dir: ./dist/*.yaml | |
format: parsable | |
config_data: "{ rules: { line-length: disable, trailing-spaces: disable } }" | |
- name: Upload YAML files | |
uses: actions/upload-artifact@v4.3.6 | |
with: | |
name: dist-files | |
#path: ./dist/*.yaml | |
path: ./dist | |
- name: Commit changes | |
uses: EndBug/add-and-commit@v9 | |
with: | |
message: Add dist files | |
committer_name: GitHub Actions | |
committer_email: 41898282+github-actions[bot]@users.noreply.github.com | |
add: './dist --force' | |
release: | |
name: Release | |
runs-on: ubuntu-latest | |
needs: build | |
permissions: | |
contents: write | |
deployments: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.inputs.branch || 'main' }} | |
- name: Get git sha | |
id: get_sha | |
run: echo "CURRENT_SHA=$(git log -1 --format='%H')" >> $GITHUB_ENV | |
- name: Check if tag exists already | |
uses: mukunku/tag-exists-action@v1.4.0 | |
id: check_tag | |
with: | |
tag: "v${{ needs.build.outputs.version }}" | |
- name: Cancel if tag is already present | |
run: | | |
echo "Tag already present: v${{ needs.build.outputs.version }}. Not creating a new release" | |
gh run cancel ${{ github.run_id }} | |
gh run watch ${{ github.run_id }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
if: steps.check_tag.outputs.exists == 'true' | |
- name: "Get previous release version" | |
id: last_release | |
uses: InsonusK/get-latest-release@v1.1.0 | |
with: | |
myToken: ${{ secrets.GITHUB_TOKEN }} | |
#exclude_types: "draft|prerelease" | |
exclude_types: "draft" | |
- name: Create new tag | |
uses: rickstaa/action-create-tag@v1.7.2 | |
id: tag_create | |
with: | |
tag: "v${{ needs.build.outputs.version }}" | |
commit_sha: "${{ env.CURRENT_SHA }}" | |
tag_exists_error: false | |
message: "Version ${{ needs.build.outputs.version }}" | |
# - name: Download artifacts | |
# uses: actions/download-artifact@v3 | |
# with: | |
# name: dist-yaml-files | |
# - name: Extract artifacts | |
# run: tar -xzf dist-yaml-files.tar.gz -C ./dist | |
# - name: Generate release changelog | |
# id: changelog | |
# uses: heinrichreimer/github-changelog-generator-action@v2.3 | |
# with: | |
# token: ${{ secrets.GITHUB_TOKEN }} | |
# sinceTag: ${{ steps.last_release.outputs.tag_name }} | |
# headerLabel: "# Notable changes since ${{ steps.last_release.outputs.tag_name }}" | |
# stripGeneratorNotice: true | |
- name: Create GitHub Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
prerelease: ${{ contains(needs.build.outputs.version, 'beta') }} | |
#body: "${{ steps.changelog.outputs.changelog }}" | |
name: "Version ${{ needs.build.outputs.version }}" | |
tag_name: "v${{ needs.build.outputs.version }}" | |
target_commitish: "${{ env.CURRENT_SHA }}" |