-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcommon.workflow.libs.frontend.yml
More file actions
124 lines (104 loc) · 4.55 KB
/
Copy pathcommon.workflow.libs.frontend.yml
File metadata and controls
124 lines (104 loc) · 4.55 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
on:
workflow_call:
inputs:
working-directory:
type: string
description: "The working directory for the job, e.g. libs/commands (without leading/trailing slash)."
required: true
secrets:
READER_TOKEN:
required: true
concurrency:
group: publish-${{ inputs.working-directory }}-${{ github.ref }}
cancel-in-progress: false # Skal ikke avbrytes av nyere samtidige deploys, da det kan føre til at versjoneringen blir feil
jobs:
build:
if: github.event.pull_request.draft == false && github.actor != 'dependabot[bot]'
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: "Checkout"
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: "Validate working directory"
run: |
if [ ! -d "./${{ inputs.working-directory }}" ]; then
echo "Directory '${{ inputs.working-directory }}' does not exist"
exit 1
fi
- name: "Setup (pnpm)"
uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5.0.0
with:
version: "latest"
- name: "Setup (Node)"
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: lts/*
registry-url: https://npm.pkg.github.com/
scope: "@navikt"
cache: pnpm
cache-dependency-path: ${{ inputs.working-directory }}/pnpm-lock.yaml
- name: "Install"
run: pnpm install --frozen-lockfile
working-directory: ${{ inputs.working-directory }}
env:
NODE_AUTH_TOKEN: ${{ secrets.READER_TOKEN }}
- name: "Build"
run: pnpm run build
working-directory: ${{ inputs.working-directory }}
- name: "Publish"
if: |
(github.ref == 'refs/heads/master' || contains(github.event.head_commit.message, '#publish-libs')) &&
(!contains(github.event.head_commit.message, '[skip ci]'))
run: |
set -eo pipefail
if [ ! -f "./package.json" ]; then
echo "No package.json found in ${{ inputs.working-directory }}"
exit 1
fi
echo "Release started by $GITHUB_ACTOR"
git config user.email "dolly@nav.no"
git config user.name "github-actions"
BRANCH_NAME="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
COMMIT_MESSAGE="${{ github.event.head_commit.message }}"
echo "Current branch: $BRANCH_NAME"
PACKAGE_NAME=$(node -p "require('./package.json').name")
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "Package: $PACKAGE_NAME"
echo "Current version in package.json: $CURRENT_VERSION"
echo "Checking if version $CURRENT_VERSION is already published..."
if pnpm view "${PACKAGE_NAME}@${CURRENT_VERSION}" version >/dev/null 2>&1; then
echo "Version $CURRENT_VERSION is already published."
if [ "$BRANCH_NAME" = "master" ] && [[ ! "$COMMIT_MESSAGE" == *"#publish-libs"* ]]; then
echo "On master branch without #publish-libs flag and version already published."
echo "This likely means the version was already published from a feature branch."
echo "Skipping publish to avoid conflict."
exit 0
fi
echo "Bumping patch version..."
pnpm version patch --no-git-tag-version
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "New version after bump: $CURRENT_VERSION"
git add package.json pnpm-lock.yaml
git commit -m "chore: bump to $CURRENT_VERSION [skip ci]"
else
echo "Version $CURRENT_VERSION not yet published."
fi
if ! git rev-parse "v$CURRENT_VERSION" >/dev/null 2>&1; then
echo "Creating tag v$CURRENT_VERSION"
git tag "v$CURRENT_VERSION"
else
echo "Tag v$CURRENT_VERSION already exists"
fi
echo "Publishing version $CURRENT_VERSION to npm registry..."
pnpm publish --no-git-checks
echo "Pushing changes to remote..."
git pull --rebase origin "$BRANCH_NAME"
git push origin "$BRANCH_NAME" --follow-tags
echo "Successfully published version $CURRENT_VERSION"
working-directory: ${{ inputs.working-directory }}
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}