{"id":13533632,"url":"https://github.com/author/action-publish","last_synced_at":"2025-04-01T22:30:31.678Z","repository":{"id":44468690,"uuid":"236050078","full_name":"author/action-publish","owner":"author","description":"Automatically publish one or more new JS module(s) to a registry.","archived":false,"fork":true,"pushed_at":"2022-10-15T19:36:19.000Z","size":1245,"stargazers_count":9,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-08T13:01:10.433Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"ButlerLogic/action-autotag","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/author.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"coreybutler","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2020-01-24T17:30:16.000Z","updated_at":"2024-02-08T04:04:30.000Z","dependencies_parsed_at":"2023-01-04T12:26:28.829Z","dependency_job_id":null,"html_url":"https://github.com/author/action-publish","commit_stats":{"total_commits":198,"total_committers":3,"mean_commits":66.0,"dds":"0.010101010101010055","last_synced_commit":"2b139130e28f780d49406101d17e17a44683432d"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/author%2Faction-publish","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/author%2Faction-publish/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/author%2Faction-publish/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/author%2Faction-publish/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/author","download_url":"https://codeload.github.com/author/action-publish/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222774628,"owners_count":17035752,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T07:01:21.599Z","updated_at":"2024-11-02T20:31:50.536Z","avatar_url":"https://github.com/author.png","language":"JavaScript","funding_links":["https://github.com/sponsors/coreybutler"],"categories":["Community Resources"],"sub_categories":["Deployment"],"readme":"# author/action-publish\n\nThis action will scan a code base and publish any public JavaScript modules it detects. It **supports publishing one _or more_ modules**, custom npm registries, npm dist-tags, and custom `.npmrc` files.\n\nModules are detected by the presence of a `package.json` file. Private packages will not be published (unless forced) and `.npmrc` files will be respected if they exist within the module's root directory.\n\nThis action was designed for workflows which require variations of a module to be published under different names. For example, a Node version and a browser version of the same library.\n\nThis action serves as the last step of a multi-phase deployment process:\n\n1. [Build \u0026 Test](https://github.com/author/template-cross-runtime) for multiple runtimes.\n1. [Autotag](https://github.com/marketplace/actions/autotagger) new versions by updating `package.json`.\n1. Publish multiple modules (i.e., this action).\n\n## Usage\n\n### Setup\n**First, you'll need an npm security token.**\n\nTo get this, [login to your npm account](https://www.npmjs.com/login) and find/create a token:\n\n\u003cimg src=\"https://docs.npmjs.com/integrations/integrating-npm-with-external-services/tokens-profile.png\" height=\"200px\"/\u003e\n\nAdditional instructions are available [here](https://docs.npmjs.com/creating-and-viewing-authentication-tokens).\n\nOnce you've created your npm token, you'll need to make your Github repo aware of it. To do this, [create an encrypted secret](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets#creating-encrypted-secrets) (called `REGISTRY_TOKEN`).\n\n### Workflow\n\nThe following is an example `.github/publish.yml` that will execute when a `release` occurs. There are other ways to run this action too (described later), but best practice is to publish whenever code is released.\n\n```yaml\nname: Publish\n\non:\n  release:\n    types:\n      - published\n      # - created\n\njobs:\n  build:\n    runs-on: ubuntu-latest\n    steps:\n    - uses: actions/checkout@v2\n    - uses: author/action-publish@stable\n      with:\n        # Optionally specify the directories to scan\n        # for modules. If this is not specified, the\n        # root directory is scanned.\n        scan: \"./dist/browser, ./dist/node\"\n        # Optionally force publishing as a public\n        # module. We don't recommend setting this,\n        # unless you have a very specific use case.\n        force: true\n      env:\n        # Typically an npm token\n        REGISTRY_TOKEN: \"${{ secrets.NPM_TOKEN }}\"\n\n```\n\nTo make this work, the workflow must have the checkout action _before_ the publish action.\n\nThis **order** is important!\n\n```yaml\n- uses: actions/checkout@v2\n- uses: author/action-publish@stable\n```\n\n\u003e If the repository is not checked out first, the publisher cannot find the `package.json` file(s).\n\n### Optional Configurations (Details)\n\nThere are several options to customize how the publisher handles operations.\n\n1. `scan`\n\n    The scan attribute tells the publish action to \"look for modules in these directories\". If this is not specified, the publish action will scan the project root. Multiple directories can be supplied using a comma-separated **string**. Do not use a YAML array (Github actions does not recognized them).\n\n    This supports glob syntax. Any `node_modules` directories are ignored automatically.\n\n    A module is detected when a `package.json` file is recognized. Private packages will not be published.\n\n    ```yaml\n    - uses: author/action-publish@stable\n      with:\n        scan: \".browser_dist, .node_dist\"\n      env:\n        REGISTRY_TOKEN: \"${{ secrets.NPM_TOKEN }}\"\n    ```\n\n1. `ignore`\n\n    The ignore attribute tells the publish action to skip any modules matching the ignored patterns.\n\n    ```yaml\n    - uses: author/action-publish@stable\n      with:\n        scan: \"./\"\n        ignore: \"**/build, **/test\"\n      env:\n        REGISTRY_TOKEN: \"${{ secrets.NPM_TOKEN }}\"\n    ```\n\n1. `force`\n\n    It's somewhat possible to force publishing, even if the `private: true` attribute is specified in a `package.json` file. Whether this option will be respected or not is dependent on the registry where the module is being published. Generally, it is not a good idea to use this option. It exists to help with edge cases, such as self-hosted private registries.\n\n    ```yaml\n    - uses: author/action-publish@stable\n      with:\n        force: true\n      env:\n        REGISTRY_TOKEN: \"${{ secrets.NPM_TOKEN }}\"\n    ```\n\n1. `dist_tag`\n\n    Set a [npm dist-tag](https://docs.npmjs.com/cli/v6/commands/npm-dist-tag) by configuring this attribute. This tag will be applied to all _non-prerelease_ versions (i.e. `x.x.x`, not `x.x.x-prerelease`).\n\n    This allows users to install your module via tag name. For example `npm install mymodule@current`.\n\n    To apply multiple tags, separate with commas.\n\n    ```yaml\n    - uses: author/action-publish@stable\n      with:\n        dist_tag: latest, current\n      env:\n        REGISTRY_TOKEN: \"${{ secrets.NPM_TOKEN }}\"\n    ```\n\n    **Notice:** npm automatically creates a `latest` tag on every publish (this attribute can override it).\n\n1. `prerelease_dist_tag`\n\n    Set a [npm dist-tag](https://docs.npmjs.com/cli/v6/commands/npm-dist-tag) for a prerelease version by configuring this attribute. This tag will be applied to all _prerelease_ versions (i.e. `x.x.x-prerelease`, not `x.x.x`).\n\n    This allows users to install your module via tag name. For example `npm install mymodule@next`.\n\n    To apply multiple tags, separate with commas.\n\n    ```yaml\n    - uses: author/action-publish@stable\n      with:\n        prerelease_dist_tag: next, beta, canary\n      env:\n        REGISTRY_TOKEN: \"${{ secrets.NPM_TOKEN }}\"\n    ```\n\n    This differs from `dist_tag` because it only applies to pre-releases.\n\n    A common approach is to set a dist-tag for prereleases so users will not automatically install a pre-release version when they want the latest stable version. In other words, running `npm install mymodule` (which is the equivalent of `npm install mymodule@latest`) should install the latest stable version while `npm install mymodule@canary` would install the latest prerelease/bleeding edge version.\n\n## Developer Notes\n\nThis action is best used as part of a complete deployment process. Consider the following workflow:\n\n```yaml\nname: Tag, Release, \u0026 Publish\n\non:\n  push:\n    branches:\n      - master\n\njobs:\n  build:\n    runs-on: ubuntu-latest\n    steps:\n      # Checkout your updatd source code\n    - uses: actions/checkout@v2\n\n      # If the version has changed, create a new git tag for it.\n    - name: Tag\n      id: autotagger\n      uses: butlerlogic/action-autotag@stable\n      with:\n        GITHUB_TOKEN: \"${{ secrets.GITHUB_TOKEN }}\"\n\n      # The remaining steps all depend on whether or  not\n      # a new tag was created. There is no need to release/publish\n      # updates until the code base is in a releaseable state.\n\n      # Create a github release\n      # This will create a snapshot of the module,\n      # available in the \"Releases\" section on Github.\n    - name: Release\n      id: create_release\n      if: steps.autotagger.outputs.tagcreated == 'yes'\n      uses: actions/create-release@v1.0.0\n      env:\n        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n      with:\n        tag_name: ${{ steps.autotagger.outputs.tagname }}\n        release_name: ${{ steps.autotagger.outputs.tagname }}\n        body: ${{ steps.autotagger.outputs.tagmessage }}\n        draft: false\n        prerelease: ${{ steps.autotagger.outputs.prerelease == 'yes' }}\n\n      # Use this action to publish a single module to npm.\n    - name: Publish\n      id: publish\n      if: steps.autotagger.outputs.tagname != ''\n      uses: author/action-publish@stable\n      env:\n        REGISTRY_TOKEN: \"${{ secrets.NPM_TOKEN }}\"\n```\n\nThe configuration above will run whenever new code is merged into the master branch. It will check the code out and use the [butlerlogic/action-autotag](https://github.com/butlerlogic/action-autotag) tag to automatically create a new git tag _if a new version is detected_. If there is no new tag, the action exits gracefully and successfully.\n\nIf a new tag exists, the action will create a new Github Release. It is smart enough to determine whether it's a prerelease or not (draft releases are not applicable to this workflow). Once the release/pre-release is created, the code is published to npm.\n\n### Multiple Node Modules\n\nIf you're using our [cross-runtime template](https://github.com/author/template-cross-runtime), then you will likely want to publish multiple versions of your module for Node.js and the browser. This requires modified pre-release, release, and publish steps.\n\n#### Releases\n\nWe like to archive each module in our releases, making it easier for developers to find prior editions they may need to function in older environents. This can be accomplished by adding a build step _after_ the release step. It may seem counterintuitive to do it after, but you'll need to create a release _before_ uploading artifacts to it.\n\n```yaml\n    - name: Build Release Artifacts\n        id: build\n        run: |\n          cd ./build \u0026\u0026 npm install \u0026\u0026 cd ../\n          npm run build --if-present\n          for d in .dist/*/*/ ; do tar -cvzf ${d%%/}-x.x.x.tar.gz ${d%%}*; done;\n\n    - name: Upload Release Artifacts\n      # This is not one of our actions\n      uses: AButler/upload-release-assets@v2.0\n      with:\n        files: './.dist/**/*.tar.gz'\n        repo-token: ${{ secrets.GITHUB_TOKEN }}\n```\n\nThe last line of the build step above looks for a directory called `.dist`. By default, the cross runtime template generates bundles in:\n\n```sh\n.dist\n  \u003e node\n    - module\n    - module\n  \u003e browsers\n    - module\n    - module\n```\n\nThe `.dist/*/*` finds all of the `module` directories and generates a tarball from them. If you do not care about taking a snapshot of these individual modules for your release, you can remove the last line.\n\nIf you do want a snapshot of your modules, none of this is necessary.\n\n#### Publishing Multiple Modules\n\nThe final publish step needs to be modified to:\n\n```yaml\n    - name: Publish\n      id: publish\n      if: steps.autotagger.outputs.tagname != ''\n      uses: author/action-publish@stable\n      with:\n        scan: './.dist'\n      env:\n        REGISTRY_TOKEN: \"${{ secrets.NPM_TOKEN }}\"\n```\n\nThe publish action will scan the `.dist` directory (and recursively scan subdirectories) to find all modules and publish them.\n\n---\n\n## Credits\n\nThis action was written and is primarily maintained by [Corey Butler](https://github.com/coreybutler).\n\n# Our Ask...\n\nIf you use this or find value in it, please consider contributing in one or more of the following ways:\n\n1. Click the \"Sponsor\" button at the top of the page.\n1. Star it!\n1. [Tweet about it!](https://twitter.com/intent/tweet?hashtags=github,actions\u0026original_referer=http%3A%2F%2F127.0.0.1%3A91%2F\u0026text=I%20am%20automating%20my%20workflow%20with%20the%20Multipublisher%20Github%20action!\u0026tw_p=tweetbutton\u0026url=https%3A%2F%2Fgithub.com%2Fauthor%2Faction%2Fpublish\u0026via=goldglovecb)\n1. Fix an issue.\n1. Add a feature (post a proposal in an issue first!).\n\nCopyright \u0026copy; 2020 Author.io, Corey Butler, and Contributors.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fauthor%2Faction-publish","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fauthor%2Faction-publish","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fauthor%2Faction-publish/lists"}