Skip to content

Commit

Permalink
first
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgamero committed Oct 30, 2023
1 parent ae5776e commit 12e20b8
Show file tree
Hide file tree
Showing 10 changed files with 359 additions and 9 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/create_js_branch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: create branch

on:
workflow_call:
inputs:
version:
required: true
type: string
description: The version of the release

jobs:
branch:
runs-on: ubuntu-latest
env:
BRANCH: releases/${{ inputs.version }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: setup git config
run: |
git config user.name "GitHub Action"
git config user.email "github-action@users.noreply.github.com"
- name: guarantee branch doesn't exist
run: |
if git ls-remote --exit-code --heads origin ${BRANCH} ; then
exit 1
else
exit 0
fi
- name: install dependencies
run: |
npm install --no-bin-links
- name: build
run: npm run build

- name: create branch
run: |
git checkout -b ${BRANCH}
git push origin ${BRANCH}
41 changes: 41 additions & 0 deletions .github/workflows/create_release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: create release

on:
workflow_call:
inputs:
branch:
required: true
type: string
description: The branch to release
version:
required: true
type: string
description: The version of the release
body:
required: true
type: string
description: The body of the release
prerelease:
required: false
default: false
type: boolean
description: Whether the release is a prerelease

jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: ncipollo/release-action@a2e71bdd4e7dab70ca26a852f29600c98b33153e # v1.12.0
with:
name: ${{ inputs.version }}
tag: ${{ inputs.version }}
body: ${{ inputs.body }}
commit: ${{ github.ref }}
prerelease: ${{ inputs.prerelease == 'prereleased' }}
39 changes: 39 additions & 0 deletions .github/workflows/extract_changelog.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: extract changelog

on:
workflow_call:
inputs:
changelogPath:
required: true
type: string
description: The path to the changelog
outputs:
version:
description: The latest version in the changelog
value: ${{ jobs.extract.outputs.version }}
body:
description: The body of the changelog
value: ${{ jobs.extract.outputs.body }}
prerelease:
description: Whether the version is in prerelease
value: ${{ jobs.extract.outputs.prerelease }}

jobs:
extract:
outputs:
version: ${{ steps.changelog.outputs.version }}
body: ${{ steps.changelog.outputs.changes }}
prerelease: ${{ steps.changelog.outputs.status == 'prereleased' }}

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: read changelog
id: changelog
uses: mindsers/changelog-reader-action@b97ce03a10d9bdbb07beb491c76a5a01d78cd3ef # v2.2.2
with:
path: ${{ inputs.changelogPath }}
33 changes: 33 additions & 0 deletions .github/workflows/nightly_release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: nightly release

on:
workflow_call:

jobs:
releaseDate:
runs-on: ubuntu-latest
outputs:
date: ${{steps.releaseDate.outputs.date}}
steps:
- name: output current date
id: releaseDate
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
switchBranch:
uses: ./.github/workflows/switch_js_branch.yaml
with:
version: nightly
createRelease:
needs: [releaseDate, switchBranch]
permissions:
contents: write
uses: ./.github/workflows/create_release.yaml
with:
branch: releases/nightly
version: nightly-${{needs.releaseDate.outputs.date}}
body: |
Nightly Build
Version: nightly-${{needs.releaseDate.outputs.date}}
Release Date: ${{needs.releaseDate.outputs.date}}
This nightly build is generated from the main branch of the repository and is not intended for testing purposes. It includes incremental changes since the last nightly build.
38 changes: 38 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: release # for releasing action-release-workflow project

on:
push:
branches:
- main
paths:
- CHANGELOG.md
workflow_dispatch:

jobs:
changelog:
uses: ./.github/workflows/extract_changelog.yaml
with:
changelogPath: ./CHANGELOG.md
checkVersion:
needs: changelog
runs-on: ubuntu-latest
outputs:
exists: ${{ steps.tag-exists.outputs.exists }}
steps:
- name: check if tag exists
uses: mukunku/tag-exists-action@5dfe2bf779fe5259360bb10b2041676713dcc8a3 # v1.1.0
id: tag-exists
with:
tag: ${{ needs.changelog.outputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
createRelease:
needs: [checkVersion, changelog]
permissions:
contents: write
if: needs.checkVersion.outputs.exists == 'false'
uses: ./.github/workflows/create_release.yaml
with:
branch: ${{ github.ref }}
version: ${{ needs.changelog.outputs.version }}
body: ${{ needs.changelog.outputs.body }}
44 changes: 44 additions & 0 deletions .github/workflows/release_js_project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: release project

on:
workflow_call:
inputs:
changelogPath:
required: true
type: string
description: The path to CHANGELOG.md

jobs:
extractChangelog:
uses: ./.github/workflows/extract_changelog.yaml
with:
changelogPath: ${{inputs.changelogPath}}
checkVersion:
needs: extractChangelog
runs-on: ubuntu-latest
outputs:
exists: ${{ steps.tag-exists.outputs.exists }}
steps:
- name: check if tag exists
uses: mukunku/tag-exists-action@5dfe2bf779fe5259360bb10b2041676713dcc8a3 # v1.1.0
id: tag-exists
with:
tag: ${{ needs.extractChangelog.outputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
createBranch:
needs: [extractChangelog, checkVersion]
if: needs.checkVersion.outputs.exists == 'false'
uses: ./.github/workflows/create_js_branch.yaml
with:
version: ${{ needs.extractChangelog.outputs.version }}
createRelease:
needs: [checkVersion, extractChangelog]
permissions:
contents: write
if: needs.checkVersion.outputs.exists == 'false'
uses: ./.github/workflows/create_release.yaml
with:
branch: release/${{ needs.extractChangelog.outputs.version }}
version: ${{ needs.extractChangelog.outputs.version }}
body: ${{ needs.extractChangelog.outputs.body }}
50 changes: 50 additions & 0 deletions .github/workflows/switch_js_branch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: switch branch # switches to `releases/nightly` branch or creates it if it doesn't exist

on:
workflow_call:
inputs:
version:
required: true
type: string
description: The version of the release

jobs:
branch:
runs-on: ubuntu-latest
env:
BRANCH: releases/${{ inputs.version }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: setup git config
run: |
git config user.name "GitHub Action"
git config user.email "github-action@users.noreply.github.com"
- name: install dependencies
run: |
npm install --no-bin-links
- name: build
run: npm run build

- name: switch or create branch
run: |
if git ls-remote --exit-code --heads origin ${BRANCH} ; then
git checkout ${BRANCH}
git checkout -b tmp origin/main
git merge -s ours ${BRANCH}
git checkout ${BRANCH}
git rm -r node_modules --ignore-unmatch
git merge tmp
git branch -D tmp
git push origin ${BRANCH}
else
git checkout -b ${BRANCH}
git push origin ${BRANCH}
fi
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,6 @@ FodyWeavers.xsd

# JetBrains Rider
*.sln.iml

# Mac Search
.DS_Store
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Change Log

## [0.0.5] - 2023-06-07
- updated release_js_project and nightly_release workflows

## [0.0.4] - 2023-06-07
- added nightly release workflow

## [0.0.3] - 2023-05-16

### Added
- input params used correctly

## [0.0.2] - 2023-05-16

### Added
- working version params?

## [0.0.1] - 2023-04-28

### Added

- Initial release of project
- Adds create_js_branch, create_release, and extract_changelog workflows
50 changes: 41 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,46 @@
# Project
# Release Workflows

> This repo has been populated by an initial template to help get you started. Please
> make sure to update the content to build a great experience for community-building.
Release Workflows automate the process of creating releases based on the CHANGELOG.md file in the project.

As the maintainer of this project, please make a few updates:
## How it works.

The release workflow is triggered when changes are pushed to the main branch and there are updates in the CHANELOG.md file. When a new release is initiated, the workflow executes the following steps:
1. It parses the CHANGELOG.md file to extract the release notes and identifies the most recent version of the release.
2. Next, it checks if a tag for the latest version already exists. If a tag is found, the subsequent workflows are halted to avoid duplication.
3. If there is no existing tag for the latest version, a new branch is created from the main branch. The new branch is named as `releases/<latest-release-version>`.
4. Once the release branch is set up, the workflow publishes the release to the GitHub repository. The release is tagged with the corresponding version number.

## Usage

1. Start by creating a CHANGELOG.md file to record the changes made in each release of your project.

2. Next, create a workflow YAML file in your project that will be triggered whenever a push is made to the main branch with changes in CHANGELOG.md file.

3. Your release.yaml workflow file should follow a structure similar to the one outlined below:

```
name: release project
on:
push:
branches:
- main
paths:
- CHANGELOG.md
workflow_dispatch:
jobs:
release:
uses: bosesuneha/action-release-workflows/.github/workflows/release_js_project.yaml@main
with:
changelogPath: ./CHANGELOG.md
```
The `release project` workflow can be triggered in two ways: automatically when changes are made to the CHANGELOG.md file and pushed to the main branch, or manually through the GitHub Actions UI.


The `release` job calls the reusable workflow in `action-release-workflows` and takes as input the path to the CHANELOG.md file.

- Improving this README.MD file to provide a great experience
- Updating SUPPORT.MD with content about this project's support experience
- Understanding the security reporting process in SECURITY.MD
- Remove this section from the README

## Contributing

Expand All @@ -30,4 +62,4 @@ This project may contain trademarks or logos for projects, products, or services
trademarks or logos is subject to and must follow
[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
Any use of third-party trademarks or logos are subject to those third-party's policies.
Any use of third-party trademarks or logos are subject to those third-party's policies.

0 comments on commit 12e20b8

Please sign in to comment.