-
Notifications
You must be signed in to change notification settings - Fork 1
127 lines (113 loc) · 4.53 KB
/
Copy pathpackage-candidate.yml
File metadata and controls
127 lines (113 loc) · 4.53 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
name: Package Candidate
on:
pull_request:
branches: [main]
types: [opened, synchronize, reopened, ready_for_review]
push:
branches: [main]
permissions:
contents: read
pull-requests: read
concurrency:
group: package-candidate-${{ github.event.pull_request.head.sha || github.sha }}
cancel-in-progress: true
jobs:
pack:
if: github.event_name == 'push' || github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
- name: Checkout candidate
uses: actions/checkout@v6
with:
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
ref: ${{ github.event.pull_request.head.sha || github.sha }}
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24
package-manager-cache: false
- name: Install dependencies
run: npm ci --allow-git=all
- name: Resolve merged pull request
id: merge
env:
HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
uses: actions/github-script@v8
with:
script: |
if (context.eventName === 'pull_request') {
core.setOutput('pr-number', String(context.payload.pull_request.number));
return;
}
const { owner, repo } = context.repo;
const { data: pullRequests } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner,
repo,
commit_sha: process.env.HEAD_SHA,
});
const merged = pullRequests.find(
(pullRequest) => pullRequest.merged_at &&
pullRequest.base.ref === context.payload.repository.default_branch &&
pullRequest.merge_commit_sha === process.env.HEAD_SHA,
);
core.setOutput('pr-number', merged ? String(merged.number) : '');
- name: Set immutable candidate versions
id: candidate
env:
HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
PR_NUMBER: ${{ steps.merge.outputs.pr-number }}
run: |
BASE_VERSION=$(node -p "require('./package.json').version.split('-')[0]")
if [ -n "$PR_NUMBER" ]; then
VERSION="${BASE_VERSION}-beta.pr${PR_NUMBER}.sha${HEAD_SHA:0:12}"
else
VERSION="${BASE_VERSION}-candidate.sha${HEAD_SHA:0:12}"
fi
export VERSION
node --input-type=module <<'NODE'
import { readFileSync } from 'node:fs';
import { execFileSync } from 'node:child_process';
const angular = JSON.parse(readFileSync('angular.json', 'utf8'));
const projects = Object.entries(angular.projects)
.filter(([, project]) => project.projectType === 'library')
.map(([name]) => name);
if (projects.length === 0) throw new Error('No Angular library projects are configured.');
for (const project of projects) {
execFileSync(
'npm',
['version', process.env.VERSION, '--no-git-tag-version', '--ignore-scripts'],
{ cwd: `projects/${project}`, stdio: 'inherit' },
);
}
NODE
echo "artifact=npm-candidate-${HEAD_SHA}" >> "$GITHUB_OUTPUT"
- name: Build all libraries
run: npm run prebuild
- name: Verify packed package entry points
run: npm run test:package-consumer
- name: Pack all library candidates
run: |
mkdir -p "$RUNNER_TEMP/npm-candidate"
node --input-type=module <<'NODE'
import { readFileSync } from 'node:fs';
import { execFileSync } from 'node:child_process';
const angular = JSON.parse(readFileSync('angular.json', 'utf8'));
const projects = Object.entries(angular.projects)
.filter(([, project]) => project.projectType === 'library')
.map(([name]) => name);
for (const project of projects) {
execFileSync(
'npm',
['pack', `./dist/${project}`, '--ignore-scripts', '--pack-destination', process.env.RUNNER_TEMP + '/npm-candidate'],
{ stdio: 'inherit' },
);
}
NODE
- name: Upload immutable package set
uses: actions/upload-artifact@v7
with:
name: ${{ steps.candidate.outputs.artifact }}
path: ${{ runner.temp }}/npm-candidate/*.tgz
if-no-files-found: error
retention-days: 7