-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: 🎡 Publish packages via GitHub Release (#8)
* ci: 🎡 Publish packages via GitHub Release * ci: WIP * ci: WIP * ci: WIP * Update package-version.sh * chore: regenerated package-lock.json * ci: WIP Co-authored-by: Maximilian Franzke <[email protected]> Co-authored-by: Maximilian Franzke <[email protected]>
- Loading branch information
1 parent
f8c575d
commit 91a81e3
Showing
10 changed files
with
465 additions
and
3,624 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
name: "Upload Tar Artifact" | ||
description: "Upload an artifact and zips it as {name}.tar.gz" | ||
inputs: | ||
name: | ||
description: "Name for artifact" | ||
required: true | ||
path: | ||
description: "Path to zip" | ||
required: true | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: 📦 Pack build as tar | ||
run: tar -czf ${{ inputs.name }} ${{ inputs.path }} | ||
shell: bash | ||
|
||
- name: ⬆ Upload build | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: ${{ inputs.name }} | ||
path: ${{ inputs.name }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [[ $GITHUB_REF == refs/tags/v* ]] | ||
then | ||
if [[ $GITHUB_ACTOR != 'dependabot[bot]' ]] | ||
then | ||
|
||
if [[ $GITHUB_PRE_RELEASE == true ]] | ||
then | ||
echo "PRE_RELEASE" | ||
elif [[ $GITHUB_COMMITISH == 'main' ]] | ||
then | ||
echo "RELEASE" | ||
fi | ||
else | ||
echo "Dependabot has no permission to publish!" | ||
exit 1 | ||
fi | ||
else | ||
echo "Your tag has to start with 'v'" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
|
||
SEMVER_VERSION=$(npx find-versions-cli "$TAG") | ||
if [[ $RELEASE == "true" ]] | ||
then | ||
if [[ $SEMVER_VERSION == *-* ]] | ||
then | ||
echo "Version $SEMVER_VERSION contains hyphen, maybe you forgot to check the prerelease checkbox in github. A release should not have a hyphen!" | ||
exit 1 | ||
fi | ||
echo "$SEMVER_VERSION" | ||
elif [[ $PRE_RELEASE == "true" ]] | ||
then | ||
GITHUB_SHA_SHORT=$(echo "$GITHUB_SHA" | cut -c1-7) | ||
VALID_SEMVER_VERSION=$(echo "$SEMVER_VERSION"-"$GITHUB_SHA_SHORT") | ||
echo "$VALID_SEMVER_VERSION" | ||
else | ||
echo "nothing found in environment for RELEASE or PRE_RELEASE" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [[ -z $VALID_SEMVER_VERSION ]]; then | ||
echo "Version is missing!" | ||
exit 1 | ||
fi | ||
|
||
if [[ $RELEASE == 'false' && $PRE_RELEASE == 'false' ]]; then | ||
echo "RELEASE and PRE_RELEASE are false, there should be an error in the pipeline!" | ||
exit 1 | ||
fi | ||
|
||
echo "🛠 Forge all packages version numbers" | ||
echo "which package version ?: $VALID_SEMVER_VERSION" | ||
|
||
npm version --no-git-tag-version "$VALID_SEMVER_VERSION" | ||
|
||
echo "📦 Create packages" | ||
npm pack --quiet | ||
|
||
TAG="latest" | ||
if [[ $PRE_RELEASE == 'true' ]]; then | ||
TAG="next" | ||
fi | ||
|
||
echo "📰 Publish Package to Registry with tag: $TAG)" | ||
for REGISTRY in 'GITHUB' 'NPM' | ||
do | ||
echo "🔒 Authenticate $REGISTRY NPM Registry" | ||
if [[ $REGISTRY == 'GITHUB' ]]; then | ||
npm config set @db-ui:registry https://npm.pkg.github.com | ||
npm set //npm.pkg.github.com/:_authToken "$GPR_TOKEN" | ||
echo "🔑 Authenticated with GITHUB" | ||
elif [[ $REGISTRY == 'NPM' ]]; then | ||
npm config set @db-ui:registry https://registry.npmjs.org/ | ||
npm set //registry.npmjs.org/:_authToken "$NPM_TOKEN" | ||
echo "🔑 Authenticated with NPM" | ||
else | ||
echo "Could not authenticate with $REGISTRY" | ||
exit 1 | ||
fi | ||
npm publish --dry-run --tag "$TAG" db-ui-base-"$VALID_SEMVER_VERSION".tgz | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,6 @@ jobs: | |
uses: actions/upload-artifact@v3 | ||
with: | ||
name: build | ||
path: public | ||
path: | | ||
public | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
name: Get and save publish version | ||
|
||
on: | ||
workflow_call: | ||
# Map the workflow outputs to job outputs | ||
outputs: | ||
release: | ||
description: "If the current tag is a release" | ||
value: ${{ jobs.publish.outputs.release }} | ||
preRelease: | ||
description: "If the current tag is a pre-release" | ||
value: ${{ jobs.publish.outputs.preRelease }} | ||
version: | ||
description: "Which version has the tag" | ||
value: ${{ jobs.publish.outputs.version }} | ||
|
||
jobs: | ||
publish: | ||
name: Get and save publish version | ||
runs-on: ubuntu-latest | ||
outputs: | ||
release: ${{ steps.releaseCheck.outputs.release }} | ||
preRelease: ${{ steps.releaseCheck.outputs.preRelease }} | ||
version: ${{ steps.getVersion.outputs.version }} | ||
steps: | ||
- name: ⬇ Checkout repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: 🔄 Init Cache | ||
uses: ./.github/actions/npm-cache | ||
|
||
- name: 💃🕺 Check if release or prerelease | ||
id: releaseCheck | ||
run: | | ||
chmod +rx ./.github/scripts/get-release.sh | ||
OUTPUT=$(./.github/scripts/get-release.sh) | ||
if [[ $OUTPUT == "RELEASE" ]]; | ||
then | ||
echo "::set-output name=release::true" | ||
elif [[ $OUTPUT == "PRE_RELEASE" ]]; | ||
then | ||
echo "::set-output name=preRelease::true" | ||
fi | ||
env: | ||
GITHUB_REF: ${{ github.ref }} | ||
GITHUB_ACTOR: ${{ github.actor }} | ||
GITHUB_COMMITISH: ${{ github.event.release.target_commitish }} | ||
GITHUB_PRE_RELEASE: ${{ github.event.release.prerelease }} | ||
|
||
- name: ↔ Extract tag name | ||
shell: bash | ||
run: echo "##[set-output name=tag;]$(echo ${GITHUB_REF#refs/tags/})" | ||
id: extractTag | ||
|
||
- name: 🏷 Get and Set Package Version on Env | ||
id: getVersion | ||
env: | ||
RELEASE: ${{ steps.releaseCheck.outputs.release }} | ||
PRE_RELEASE: ${{ steps.releaseCheck.outputs.preRelease }} | ||
TAG: ${{ steps.extractTag.outputs.tag }} | ||
run: | | ||
chmod +rx ./.github/scripts/package-version.sh | ||
OUTPUT=$(./.github/scripts/package-version.sh) | ||
echo "::set-output name=version::$OUTPUT" | ||
- name: 🌳 Log Valid Version | ||
env: | ||
VALID_SEMVER_VERSION: ${{ steps.getVersion.outputs.version }} | ||
run: echo "$VALID_SEMVER_VERSION" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--- | ||
name: Publish all Packages to Registries | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
release: | ||
required: false | ||
default: "false" | ||
type: string | ||
preRelease: | ||
required: false | ||
default: "false" | ||
type: string | ||
version: | ||
required: true | ||
type: string | ||
|
||
jobs: | ||
publish: | ||
name: Publish latest package versions to GitHub Packages | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
steps: | ||
- name: ⬇ Checkout repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: 🔄 Init Cache | ||
uses: ./.github/actions/npm-cache | ||
|
||
- name: ⬇️Download package build | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: build | ||
path: ./ | ||
|
||
- name: 📰 Publish to NPM Registries | ||
run: | | ||
chmod +rx ./.github/scripts/publish-npm.sh | ||
./.github/scripts/publish-npm.sh | ||
env: | ||
RELEASE: ${{ inputs.release }} | ||
PRE_RELEASE: ${{ inputs.preRelease }} | ||
VALID_SEMVER_VERSION: ${{ inputs.version }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
GPR_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: ⬆ Upload Package Artifact db-ui-base | ||
uses: ./.github/actions/upload-tar-artifact | ||
with: | ||
name: package-base-tgz | ||
path: db-ui-base-${{ inputs.version }}.tgz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Test and publish to package registries after new GitHub release | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
init: | ||
uses: ./.github/workflows/00-init.yml | ||
|
||
get-publish-version: | ||
uses: ./.github/workflows/01-get-publish-version.yml | ||
needs: [init] | ||
|
||
# TODO: Reactivate when test and lint works | ||
# lint: | ||
# uses: ./.github/workflows/01-lint.yml | ||
# needs: [init] | ||
# | ||
# test: | ||
# uses: ./.github/workflows/01-test.yml | ||
# needs: [init] | ||
|
||
build: | ||
uses: ./.github/workflows/01-build.yml | ||
needs: [init] | ||
|
||
publishpackages: | ||
uses: ./.github/workflows/03-publish-packages.yml | ||
needs: [build, get-publish-version] | ||
secrets: inherit | ||
with: | ||
release: ${{ needs.get-publish-version.outputs.release }} | ||
preRelease: ${{ needs.get-publish-version.outputs.preRelease }} | ||
version: ${{ needs.get-publish-version.outputs.version }} |
Oops, something went wrong.