Repository navigation
66 lines (62 loc) · 2.61 KB
/
Copy pathgithub-packages.yml
File metadata and controls
66 lines (62 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
name: GitHub Packages
on:
workflow_dispatch:
inputs:
tag:
description: Published release tag to mirror, e.g. v0.1.0
required: true
type: string
workflow_call:
inputs:
tag:
required: true
type: string
permissions:
contents: read
packages: write
concurrency:
group: github-package-${{ inputs.tag }}
cancel-in-progress: false
jobs:
publish:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
registry-url: https://npm.pkg.github.com
scope: '@${{ github.repository_owner }}'
- name: Download the verified release inputs
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ inputs.tag }}
run: |
node -e 'if(!/^v\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?$/.test(process.env.RELEASE_TAG)) throw new Error("Use a semantic version tag such as v0.1.0")'
mkdir -p "$RUNNER_TEMP/github-package-download"
gh release download "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" --dir "$RUNNER_TEMP/github-package-download" --pattern "mori-study-${RELEASE_TAG#v}.tgz" --pattern SHA256SUMS.txt
- name: Prepare the repository-linked package
id: package
env:
RELEASE_TAG: ${{ inputs.tag }}
run: |
node scripts/github-package.mjs --source "$RUNNER_TEMP/github-package-download" --output "$RUNNER_TEMP/github-package" --repository "$GITHUB_REPOSITORY" --tag "$RELEASE_TAG" >> "$GITHUB_OUTPUT"
- name: Publish to GitHub Packages
env:
NODE_AUTH_TOKEN: ${{ github.token }}
PACKAGE_NAME: ${{ steps.package.outputs.name }}
PACKAGE_VERSION: ${{ steps.package.outputs.version }}
PACKAGE_DIRECTORY: ${{ steps.package.outputs.directory }}
run: |
if npm view "$PACKAGE_NAME@$PACKAGE_VERSION" version --registry=https://npm.pkg.github.com >/dev/null 2>&1; then
echo "$PACKAGE_NAME@$PACKAGE_VERSION is already published."
else
npm publish "$PACKAGE_DIRECTORY" --registry=https://npm.pkg.github.com --ignore-scripts
fi
- name: Confirm repository connection and visibility
env:
GH_TOKEN: ${{ github.token }}
run: |
gh api "/users/$GITHUB_REPOSITORY_OWNER/packages/npm/mori-study" --jq '{name, visibility, html_url, repository: .repository.full_name}'
echo 'Package publication completed. Verify Public visibility in the package metadata above; Package settings provides visibility controls.' >> "$GITHUB_STEP_SUMMARY"