Repository navigation
89 lines (80 loc) · 3.31 KB
/
Copy pathfe-pr-snapshot.yml
File metadata and controls
89 lines (80 loc) · 3.31 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
name: Frontend Pull Request Snapshot Workflow
on:
workflow_call:
inputs:
GHA_BASE:
type: string
required: true
secrets:
JFROG_BASE64_TOKEN:
required: true
JFROG_URL:
required: true
JFROG_USER:
required: true
DOT_NPMRC:
required: true
jobs:
publish-pr-snapshot:
if: contains(github.event.pull_request.labels.*.name, 'snapshot')
runs-on: ubuntu-latest
env:
NODE_OPTIONS: --max-old-space-size=4096
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: 22.15.0
- name: Cache Node Modules
id: npm-cache
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }}
- name: Validate and fetch base branch
run: |
BASE_BRANCH="${{ inputs.GHA_BASE }}"
echo "Validating base branch: $BASE_BRANCH"
if git fetch origin "$BASE_BRANCH:$BASE_BRANCH" 2>/dev/null; then
echo "✅ Base branch fetched successfully"
echo "VALIDATED_BASE=$BASE_BRANCH" >> $GITHUB_ENV
else
echo "❌ Base branch '$BASE_BRANCH' not found, using default"
DEFAULT_BRANCH=$(git remote show origin | grep 'HEAD branch' | cut -d' ' -f5)
git fetch origin "$DEFAULT_BRANCH:$DEFAULT_BRANCH"
echo "VALIDATED_BASE=$DEFAULT_BRANCH" >> $GITHUB_ENV
fi
- name: Use .npmrc
uses: collaborationFactory/github-actions/.github/actions/use-npmrc@release/25.4
with:
dot-npmrc: ${{ secrets.DOT_NPMRC }}
- name: Install modules
if: steps.npm-cache.outputs.cache-hit != 'true'
run: npm ci
- name: Build and Push to Jfrog NPM Registry
uses: collaborationFactory/github-actions/.github/actions/artifacts@release/25.4
env:
JFROG_BASE64_TOKEN: ${{ secrets.JFROG_BASE64_TOKEN }}
JFROG_URL: ${{ secrets.JFROG_URL }}
JFROG_USER: ${{ secrets.JFROG_USER }}
BASE: ${{ env.VALIDATED_BASE }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
PR_NUMBER: ${{ github.event.number }}
- name: comment published Artifacts on PR
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const fs = require('fs');
const marker = '<!-- published-artifacts -->';
const body = marker + '\n' + fs.readFileSync('githubCommentsForPR.txt', 'utf8');
const { data: comments } = await github.rest.issues.listComments({
...context.repo, issue_number: context.issue.number });
const existing = comments.find(c => c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({ ...context.repo, comment_id: existing.id, body });
} else {
await github.rest.issues.createComment({ ...context.repo, issue_number: context.issue.number, body });
}