Skip to content

Commit

Permalink
feat: workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
gbertoncelli committed Feb 20, 2024
1 parent 3959b07 commit 061abe0
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 4 deletions.
130 changes: 130 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: Create new release

on:
pull_request:
branches:
- main
types: [closed]
workflow_dispatch:
inputs:
semver:
description: "Semver version"
required: true
default: "minor"

jobs:
create:
name: Create PR for new release
if: github.event.inputs.semver
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.REPO_ACCESS }}

- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: "20.x"
registry-url: https://npm.pkg.github.com/
scope: "@ctinnovation"

- name: install dependencies
run: npm install -g @ctinnovation/changelogger
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_GET_TOKEN}}

- name: setup git config
run: |
# setup the username and email. I tend to use 'GitHub Actions Bot' with no email by default
git config user.name "GitHub Actions Bot"
git config user.email "<github@ctinnovation.it>"
- name: update version and changelog
run: |
npm version ${{ github.event.inputs.semver }} --no-git-tag-version
- name: Get new version from package.json
run: |
pkg_version=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]')
echo "PACKAGE_VERSION=$pkg_version" >> $GITHUB_ENV
echo $PACKAGE_VERSION
- name: Create pull request
id: pr-create
uses: actions/github-script@v6
with:
github-token: ${{ github.token }}
script: |
const res = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
ref: "refs/tags/tagname",
head: "release_${{ env.PACKAGE_VERSION }}",
base: "main",
title: "Release: [v${{ env.PACKAGE_VERSION }}]",
body: `PR created by Github Actions bot in order to release new version **v${{ env.PACKAGE_VERSION }}**.`
})
return res.data.number;
- name: Request and assign review
uses: actions/github-script@v6
with:
github-token: ${{ github.token }}
script: |
await github.rest.pulls.requestReviewers({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: ${{ steps.pr-create.outputs.result }},
reviewers: ['${{ github.actor }}']
});
await github.rest.issues.addAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ steps.pr-create.outputs.result }},
assignees: ['${{ github.actor }}']
});
publish:
name: Tagging and publish new release
runs-on: ubuntu-latest
if: (github.event.pull_request.merged == true) && (startsWith(github.event.pull_request.title, 'Release:'))
steps:
- run: |
echo ${{ github.event.pull_request.title}}
echo "TAG=$(echo '${{ github.event.pull_request.title}}' | awk -F '[][]' '{print $2}')" >> $GITHUB_ENV
- name: Checkout
if: "${{ env.TAG }}"
uses: actions/checkout@v4
with:
token: ${{ secrets.REPO_ACCESS }}

- name: Tagging
if: "${{ env.TAG }}"
run: |
git tag ${{ env.TAG }}
git push origin --tags
- name: Create and publish release on tag
if: "${{ env.TAG }}"
uses: actions/github-script@v6
with:
github-token: ${{ github.token }}
script: |
github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: "${{ env.TAG }}",
target_commitish: "${{ github.sha}}",
name: "${{ env.TAG }}"
})
- name: NPM package publish
if: "${{ env.TAG }}"
run: |
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

Have a lot of packages on your GitHub account? Explore them smoothly with gitstronaut 🚀

### Installation

This tool needs [NodeJS](https://nodejs.org/en) and it is tested with node version `20.X`.

```bash
npm i -g gitstronaut
gitstronaut explore
```

### Authentication

There are two ways to authenticate with this CLI:
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"name": "gitstronaut",
"version": "1.0.0",
"version": "0.0.0",
"description": "",
"main": "index.mjs",
"type": "module",
"scripts": {
"test": "exit 0"
"test": "exit 0",
"version": "git branch -D 'release_'$npm_package_version || true && git checkout -b 'release_'$npm_package_version && changelogger -p && git add .",
"postversion": "git commit -mv$npm_package_version && git push --set-upstream origin 'release_'$npm_package_version"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -40,4 +42,4 @@
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-promise": "^6.1.1"
}
}
}
Empty file added unreleased/.gitkeep
Empty file.

0 comments on commit 061abe0

Please sign in to comment.