Skip to content

Commit 8e0088e

Browse files
dkolbamfranzke
andauthored
ci: 🎡 Publish packages via CI (#15)
* ci: 🎡 Publish packages via CI * Update package-version.sh * Update get-release.sh Co-authored-by: Maximilian Franzke <[email protected]>
1 parent d272e4a commit 8e0088e

11 files changed

+624
-3761
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
name: "Upload Tar Artifact"
3+
description: "Upload an artifact and zips it as {name}.tar.gz"
4+
inputs:
5+
name:
6+
description: "Name for artifact"
7+
required: true
8+
path:
9+
description: "Path to zip"
10+
required: true
11+
runs:
12+
using: "composite"
13+
steps:
14+
- name: 📦 Pack build as tar
15+
run: tar -czf ${{ inputs.name }} ${{ inputs.path }}
16+
shell: bash
17+
18+
- name: ⬆ Upload build
19+
uses: actions/upload-artifact@v3
20+
with:
21+
name: ${{ inputs.name }}
22+
path: ${{ inputs.name }}

.github/scripts/get-release.sh

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ $GITHUB_REF == refs/tags/v* ]]
4+
then
5+
if [[ $GITHUB_ACTOR != 'dependabot[bot]' ]]
6+
then
7+
8+
if [[ $GITHUB_PRE_RELEASE == true ]]
9+
then
10+
echo "PRE_RELEASE"
11+
elif [[ $GITHUB_COMMITISH == 'main' ]]
12+
then
13+
echo "RELEASE"
14+
fi
15+
else
16+
echo "Dependabot has no permission to publish!"
17+
exit 1
18+
fi
19+
else
20+
echo "Your tag has to start with 'v'"
21+
exit 1
22+
fi

.github/scripts/package-version.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
SEMVER_VERSION=$(npx find-versions-cli "$TAG")
4+
if [[ $RELEASE == "true" ]]
5+
then
6+
if [[ $SEMVER_VERSION == *-* ]]
7+
then
8+
echo "Version $SEMVER_VERSION contains hyphen, maybe you forgot to check the prerelease checkbox in github. A release should not have a hyphen!"
9+
exit 1
10+
fi
11+
echo "$SEMVER_VERSION"
12+
elif [[ $PRE_RELEASE == "true" ]]
13+
then
14+
GITHUB_SHA_SHORT=$(echo "$GITHUB_SHA" | cut -c1-7)
15+
VALID_SEMVER_VERSION=$(echo "$SEMVER_VERSION"-"$GITHUB_SHA_SHORT")
16+
echo "$VALID_SEMVER_VERSION"
17+
else
18+
echo "nothing found in environment for RELEASE or PRE_RELEASE"
19+
exit 1
20+
fi

.github/scripts/publish-npm.sh

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ -z $VALID_SEMVER_VERSION ]]; then
4+
echo "Version is missing!"
5+
exit 1
6+
fi
7+
8+
if [[ $RELEASE == 'false' && $PRE_RELEASE == 'false' ]]; then
9+
echo "RELEASE and PRE_RELEASE are false, there should be an error in the pipeline!"
10+
exit 1
11+
fi
12+
13+
echo "🛠 Forge all packages version numbers"
14+
echo "which package version ?: $VALID_SEMVER_VERSION"
15+
16+
npm version --no-git-tag-version "$VALID_SEMVER_VERSION"
17+
18+
echo "📦 Create packages"
19+
npm pack --quiet
20+
21+
TAG="latest"
22+
if [[ $PRE_RELEASE == 'true' ]]; then
23+
TAG="next"
24+
fi
25+
26+
echo "📰 Publish Package to Registry with tag: $TAG)"
27+
for REGISTRY in 'GITHUB' 'NPM'
28+
do
29+
echo "🔒 Authenticate $REGISTRY NPM Registry"
30+
if [[ $REGISTRY == 'GITHUB' ]]; then
31+
npm config set @db-ui:registry https://npm.pkg.github.com
32+
npm set //npm.pkg.github.com/:_authToken "$GPR_TOKEN"
33+
echo "🔑 Authenticated with GITHUB"
34+
elif [[ $REGISTRY == 'NPM' ]]; then
35+
npm config set @db-ui:registry https://registry.npmjs.org/
36+
npm set //registry.npmjs.org/:_authToken "$NPM_TOKEN"
37+
echo "🔑 Authenticated with NPM"
38+
else
39+
echo "Could not authenticate with $REGISTRY"
40+
exit 1
41+
fi
42+
npm publish --dry-run --tag "$TAG" db-ui-core-"$VALID_SEMVER_VERSION".tgz
43+
done

.github/workflows/01-build.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,16 @@ jobs:
1717
- name: 🍼 Create pages build
1818
run: npm run build
1919

20-
- name: ⬆️Upload build
20+
- name: ⬆️Upload page build
2121
uses: actions/upload-artifact@v3
2222
with:
2323
name: build
2424
path: public
25+
26+
- name: ⬆️Upload package build
27+
uses: actions/upload-artifact@v3
28+
with:
29+
name: package
30+
path: |
31+
dist/
32+
sources/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
name: Get and save publish version
3+
4+
on:
5+
workflow_call:
6+
# Map the workflow outputs to job outputs
7+
outputs:
8+
release:
9+
description: "If the current tag is a release"
10+
value: ${{ jobs.publish.outputs.release }}
11+
preRelease:
12+
description: "If the current tag is a pre-release"
13+
value: ${{ jobs.publish.outputs.preRelease }}
14+
version:
15+
description: "Which version has the tag"
16+
value: ${{ jobs.publish.outputs.version }}
17+
18+
jobs:
19+
publish:
20+
name: Get and save publish version
21+
runs-on: ubuntu-latest
22+
outputs:
23+
release: ${{ steps.releaseCheck.outputs.release }}
24+
preRelease: ${{ steps.releaseCheck.outputs.preRelease }}
25+
version: ${{ steps.getVersion.outputs.version }}
26+
steps:
27+
- name: ⬇ Checkout repo
28+
uses: actions/checkout@v3
29+
30+
- name: 🔄 Init Cache
31+
uses: ./.github/actions/npm-cache
32+
33+
- name: 💃🕺 Check if release or prerelease
34+
id: releaseCheck
35+
run: |
36+
chmod +rx ./.github/scripts/get-release.sh
37+
OUTPUT=$(./.github/scripts/get-release.sh)
38+
if [[ $OUTPUT == "RELEASE" ]];
39+
then
40+
echo "::set-output name=release::true"
41+
elif [[ $OUTPUT == "PRE_RELEASE" ]];
42+
then
43+
echo "::set-output name=preRelease::true"
44+
fi
45+
env:
46+
GITHUB_REF: ${{ github.ref }}
47+
GITHUB_ACTOR: ${{ github.actor }}
48+
GITHUB_COMMITISH: ${{ github.event.release.target_commitish }}
49+
GITHUB_PRE_RELEASE: ${{ github.event.release.prerelease }}
50+
51+
- name: ↔ Extract tag name
52+
shell: bash
53+
run: echo "##[set-output name=tag;]$(echo ${GITHUB_REF#refs/tags/})"
54+
id: extractTag
55+
56+
- name: 🏷 Get and Set Package Version on Env
57+
id: getVersion
58+
env:
59+
RELEASE: ${{ steps.releaseCheck.outputs.release }}
60+
PRE_RELEASE: ${{ steps.releaseCheck.outputs.preRelease }}
61+
TAG: ${{ steps.extractTag.outputs.tag }}
62+
run: |
63+
chmod +rx ./.github/scripts/package-version.sh
64+
OUTPUT=$(./.github/scripts/package-version.sh)
65+
echo "::set-output name=version::$OUTPUT"
66+
67+
- name: 🌳 Log Valid Version
68+
env:
69+
VALID_SEMVER_VERSION: ${{ steps.getVersion.outputs.version }}
70+
run: echo "$VALID_SEMVER_VERSION"

.github/workflows/01-lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ jobs:
1414
- name: 🔄 Init Cache
1515
uses: ./.github/actions/npm-cache
1616

17-
- name: ⚡ Run Test
17+
- name: ⚡ Run Lint
1818
run: npm run lint
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
name: Publish all Packages to Registries
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
release:
8+
required: false
9+
default: "false"
10+
type: string
11+
preRelease:
12+
required: false
13+
default: "false"
14+
type: string
15+
version:
16+
required: true
17+
type: string
18+
19+
jobs:
20+
publish:
21+
name: Publish latest package versions to GitHub Packages
22+
runs-on: ubuntu-latest
23+
strategy:
24+
fail-fast: false
25+
steps:
26+
- name: ⬇ Checkout repo
27+
uses: actions/checkout@v3
28+
29+
- name: 🔄 Init Cache
30+
uses: ./.github/actions/npm-cache
31+
32+
- name: ⬇️Download package build
33+
uses: actions/download-artifact@v3
34+
with:
35+
name: package
36+
path: ./
37+
38+
- name: 📰 Publish to NPM Registries
39+
run: |
40+
chmod +rx ./.github/scripts/publish-npm.sh
41+
./.github/scripts/publish-npm.sh
42+
env:
43+
RELEASE: ${{ inputs.release }}
44+
PRE_RELEASE: ${{ inputs.preRelease }}
45+
VALID_SEMVER_VERSION: ${{ inputs.version }}
46+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
47+
GPR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
49+
- name: ⬆ Upload Package Artifact db-uicore
50+
uses: ./.github/actions/upload-tar-artifact
51+
with:
52+
name: package-core
53+
path: db-ui-core-${{ inputs.version }}.tgz

.github/workflows/release.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Test and publish to package registries after new GitHub release
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
init:
9+
uses: ./.github/workflows/00-init.yml
10+
11+
get-publish-version:
12+
uses: ./.github/workflows/01-get-publish-version.yml
13+
needs: [init]
14+
15+
lint:
16+
uses: ./.github/workflows/01-lint.yml
17+
needs: [init]
18+
19+
test:
20+
uses: ./.github/workflows/01-test.yml
21+
needs: [init]
22+
23+
build:
24+
uses: ./.github/workflows/01-build.yml
25+
needs: [init]
26+
27+
publishpackages:
28+
uses: ./.github/workflows/03-publish-packages.yml
29+
needs: [build, get-publish-version]
30+
secrets: inherit
31+
with:
32+
release: ${{ needs.get-publish-version.outputs.release }}
33+
preRelease: ${{ needs.get-publish-version.outputs.preRelease }}
34+
version: ${{ needs.get-publish-version.outputs.version }}

0 commit comments

Comments
 (0)