Skip to content

Commit

Permalink
split workflow files
Browse files Browse the repository at this point in the history
  • Loading branch information
Eslam3bed committed Sep 22, 2024
1 parent c223b30 commit 5a51a26
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 1 deletion.
64 changes: 64 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Build and Release

on:
push:
branches:
- main

permissions:
contents: write

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Install dependencies
run: npm install

- name: Run tests
run: npm run test

- name: Build the package
run: npm run build

- name: Bump version and generate changelog
run: |
git config --global user.name 'Eslam3bed'
git config --global user.email '[email protected]'
npm run release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Commit changelog and version bump
id: commit_version
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
# Check if there are any changes to commit
if ! git diff --quiet; then
git add .
git commit -m "chore(release): $(node -p -e "require('./package.json').version") [skip ci]"
git tag v$(node -p -e "require('./package.json').version")
echo "version_bumped=true" >> $GITHUB_ENV
else
echo "No changes to commit."
echo "version_bumped=false" >> $GITHUB_ENV
fi
- name: Push changes to main branch
if: env.version_bumped == 'true'
run: |
git checkout main
git push origin main --follow-tags
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 4 additions & 1 deletion .github/workflows/ci-cd.yml → .github/workflows/ci-cd.Xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ jobs:
echo "::set-output name=version_bumped::true"
fi
- name: Push changes to main branch
run: git push --follow-tags
if: env.version_bumped == 'true'
run: |
git checkout main
git push origin main --follow-tags
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Publish

on:
release:
types: [published]

permissions:
contents: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Tag the repository
id: tag
run: |
TAG=v$(date -Iseconds | sed 's/[T:\+]/-/g')
echo "$TAG"
echo "tag=$TAG" >> $GITHUB_OUTPUT
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git tag -a $TAG -m "Published version $TAG" ${GITHUB_SHA}
git push origin $TAG
- name: Publish to npm
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Create a release on GitHub
uses: softprops/action-gh-release@v1
with:
files: dist/*
tag_name: ${{ steps.tag.outputs.tag }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 5a51a26

Please sign in to comment.