Skip to content

Commit

Permalink
Adding release pipeline (#174)
Browse files Browse the repository at this point in the history
* Fixing release  checkout

* Fixing release checkout step

* Changing package version

* fixing version stuff

* Switching to a different task

* fixing step

* fixng step

* Fixing stuff

* switch task

* Fixing release

* Fixing release updated task

* switching to checking tags

* fixing previous tag

* Fixing release notes

* Fixing stuff

* Always printing stuff

* Fixing stuff

* changing fetch depth to get all tags

* printing rel notes

* Adding double quotes

* Printing stuff

* fixing stuff

* Fixing spacing
  • Loading branch information
aasimkhan30 authored Aug 10, 2024
1 parent 41d40cf commit c7a9ced
Showing 1 changed file with 42 additions and 22 deletions.
64 changes: 42 additions & 22 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ permissions:
actions: read
checks: write
deployments: write
packages: write

jobs:
build-and-test:
Expand All @@ -28,16 +29,20 @@ jobs:

- name: Install Dependencies
run: npm install

- name: Check if package.json has changed
id: check
- name: Check if tag is present
id: tag_check
run: |
if [ $(git diff --name-only HEAD^1 HEAD | grep 'package.json' | wc -l) -eq 0 ]; then
echo "No version change detected in package.json."
VERSION=$(jq -r '.version' package.json)
echo "version=${VERSION}" >> $GITHUB_ENV
if git rev-parse "${VERSION}" >/dev/null 2>&1; then
echo "Tag v${VERSION} already exists."
echo "exists=true" >> $GITHUB_ENV
else
echo "Version change detected."
echo "Tag v${VERSION} does not exist."
echo "exists=false" >> $GITHUB_ENV
fi
- name: Create npm package
run: npm pack

Expand All @@ -47,39 +52,54 @@ jobs:

- name: Checkout release branch
uses: actions/checkout@v4
ref: release
path: './release'
with:
ref: release
path: ./release
fetch-depth: 0

- name: Extract package contents
run: |
tar -xzf *.tgz --strip-components=1 -C ./release
- name: Set up Git use
run: |
git config --global user.email "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Push package contents to a new branch
run: |
VERSION=$(jq -r '.version' package.json)
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
cd ./release
git add .
git commit -m "Release ${VERSION}"
git commit -m "Release v${{ env.version }}"
echo "Pushing with message: Release v${{ env.version }}"
git push origin release
- name: Generate release notes
run: |
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^1)
cd ./release
PREV_TAG=$(git describe --tags --abbrev=0)
echo "${PREV_TAG}"
GIT_LOG=$(git log --pretty=format:"%h - %s (%an)" "${PREV_TAG}..HEAD")
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
echo "${GIT_LOG}" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Printing release notes
if: always()
run: |
echo ${{ env.RELEASE_NOTES }}
echo ${{ env.GIT_LOG }}
echo ${{ env.RELEASE_NOTES }}
echo v${{ steps.check.outputs.version }}
echo " ${{ env.RELEASE_NOTES }} "
echo v${{ env.version }}
echo ${{ env.exists }}
- name: Create Release
if: env.exists == 'false'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.version }}
release_name: Release v${{ env.version }}
body: ${{ env.RELEASE_NOTES }}
draft: false
prerelease: false
commitish: release



0 comments on commit c7a9ced

Please sign in to comment.