Skip to content

get tag_branch_name in the workflow file #72

get tag_branch_name in the workflow file

get tag_branch_name in the workflow file #72

Workflow file for this run

name: Publish
on:
pull_request:
paths:
- "index*.ts"
- "test/**"
- ".github/workflows/publish.yml"
- "package.json"
workflow_dispatch:
push:
branches:
- main
paths:
- "index.ts"
- "README.md"
- ".github/workflows/publish.yml"
- "package.json"
tags:
- "v*"
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
TAG_BRANCH: ${{ env.TAG_BRANCH_NAME }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- id: prepare_env
run: |
echo "TAGGED=${{ startsWith(github.ref, 'refs/tags/v') }}" >> $GITHUB_ENV
SHORT_SHA=$(git rev-parse --short HEAD)
echo "SHORT_SHA=$SHORT_SHA" >> $GITHUB_ENV
RAW=$(git branch -r --contains $GITHUB_REF)
TAG_BRANCH_NAME="${RAW##*/}"
echo "TAG_BRANCH_NAME=$TAG_BRANCH_NAME" >> $GITHUB_ENV
- run: echo "${{ toJSON(env) }}"
test:
name: test on Node.js ${{ matrix.node-version }}
runs-on: ubuntu-latest
needs: prepare
strategy:
fail-fast: true
matrix:
node-version:
- 16
- 18
- 20
steps:
- uses: actions/checkout@v3
- name: Set Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- uses: actions/cache@v3
id: cache-deps
with:
path: |
**/node_modules
key: ${{ runner.os }}-${{ matrix.node-version }}-modules-${{ hashFiles('**/yarn.lock') }}
- name: install dependencies
uses: borales/actions-yarn@v4
with:
cmd: install
- name: build package
uses: borales/actions-yarn@v4
with:
cmd: build
- name: build types
uses: borales/actions-yarn@v4
with:
cmd: tsc
- name: test types
uses: borales/actions-yarn@v4
with:
cmd: tsd
- name: test functionality
uses: borales/actions-yarn@v4
with:
cmd: test
- uses: actions/upload-artifact@v3
with:
name: lib
path: lib
publish:
name: Publish to npmjs
runs-on: ubuntu-latest
needs: [prepare, test]
if: ${{ needs.prepare.outputs.TAG_BRANCH == 'main' && startsWith(github.ref, 'refs/tags/v') }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "16.x"
- uses: actions/download-artifact@v3
with:
name: lib
path: lib
- uses: heinrichreimer/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: JS-DevTools/npm-publish@v2
with:
token: ${{ secrets.NPM_TOKEN }}
access: public
- uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
files: |
./lib/**
- uses: stefanzweifel/git-auto-commit-action@v4
with:
create_branch: true
branch: "changelog-${{ github.run_id }}"