GitHub Action
npm-semver-publish
- generate an access token able to make commits, tags and push them (see Managing your personal access tokens)
- add the above generated token in the secret ACTION_TOKEN (see Using secrets in GitHub Actions)
- generate a new npm token able to publish Creating and viewing access tokens
- add the above generated token in the secret NPM_TOKEN (see Using secrets in GitHub Actions)
After generating and storing the above tokens, to include the npm-semver-publish-action in your workflow in your repository, simply add the following script in your action yaml file:
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.ACTION_TOKEN }}
- uses: fregante/setup-git-user@v2 #used to add to git config user and mail
uses: actions/setup-node@v4
- name: Run my Action
id: run-action
uses: actions/npm-semver-publish-action@v1
with:
node-version: 20.x
registry-url: 'https://registry.npmjs.org'
target-branch: 'master'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Below a complete job example:
on:
push:
branches: main
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.ACTION_TOKEN }}
- uses: fregante/setup-git-user@v2
uses: actions/setup-node@v4
- name: Run my Action
id: run-action
uses: actions/npm-semver-publish-action@v1
with:
node-version: 20.x
registry-url: 'https://registry.npmjs.org'
target-branch: 'master'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Name | Type | Default | Description |
---|---|---|---|
target-branch | string | master | Branch name where npm publish with semanantic versioning should be applied to the GitHub Action execution |
registry-url | string | no-value | Registry to publish your package |
node-version | string | no-value | node version to execute the action |
-
🛠️ Install the dependencies
npm install
-
🏗️ Package the JavaScript for distribution
npm run bundle
-
✅ Run the tests
npm test
GitHub Actions Toolkit documentation.
-
Create a new branch
-
Update the contents of
src/
-
Add tests to
__tests__/
-
Format, test, and build the action
npm run all
[!WARNING]
This step is important! It will run
ncc
to build the final JavaScript action code with all dependencies included. If you do not run this step, your action will not work correctly when it is used in a workflow. This step also includes the--license
option forncc
, which will create a license file for all of the production node modules used in your project. -
Commit your changes
git add . git commit -m "My first action is ready!"
-
Push them to your repository
git push -u origin releases/v1
-
Create a pull request and get feedback on your action
-
Merge the pull request into the
main
branch
You can now validate the action by referencing it in a workflow file. For
example, ci.yml
demonstrates how to reference an
action in the same repository.
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v3
- name: Test Local Action
id: test-action
uses: ./
with:
target-branch: 'release'
- name: Print Output
id: output
run: echo "${{ steps.test-action.outputs.version }}"
CSVtoJSON is licensed under the GNU General Public License v3.0 License.
Just if you want to support this repository:
- BTC tip address: 37vdjQhbaR7k7XzhMKWzMcnqUxfw1njBNk