0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Gitub actionsでGithub packageをnpm installする

Posted at

前提

Install 対象のGithub packageも、Installを行うプロジェクトもどちらも同じアカウント(スコープ)内に存在する場合が対象です。

PATを散りばめたくなかったので、GITHUB_TOKEN利用に限定した設定とGithub workflow記述となります。

Github package

Github package側で、Installを許可するリポジトリを指定します。

Package ランディングページ

Package settings

Manage Actions access

リポジトリを選択し、readアクセスを与える。

Github action workflow

チェックアウトした.npmrcに、${{ secrets.GITHUB_TOKEN }}を追記します。

workflow.yaml
on: push

jobs:
  install-package:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      // Add the token value into .npmrc
      - run: echo -e "\n//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> ./.npmrc
      - name: Use Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 18.x
      - run: npm i

.npmrcは以下のようになります。

.npmrc
# GITHUB_TOKEN:Action時に自動で付与される値
# MY_ACCOUNT:アカウント名
//npm.pkg.github.com/:_authToken=GITHUB_TOKEN
@MY_ACCOUNT:registry=https://npm.pkg.github.com

最後に

上記のGithub packageGithub actionsへの設定追加で、同アカウント内というケースで、Package installが可能となります。

これが、異なるアカウント間の場合はPATが必要になってきます。

参考

Stack overflowに質問

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?