Skip to content

Commit

Permalink
task: setup GHA
Browse files Browse the repository at this point in the history
  • Loading branch information
cngJo committed May 30, 2023
1 parent 5128e7a commit f6d0f61
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 11 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: "Build 🏗️"

on:
workflow_call:

jobs:
build:
name: "Build"
runs-on: ubuntu-latest

steps:
- name: "Checkout"
uses: actions/checkout@v3

- name: "Setup NodeJS"
uses: actions/setup-node@v3
with:
node-version: "18"

- uses: pnpm/action-setup@v2
name: Install pnpm
id: pnpm-install
with:
version: 7
run_install: false

- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --strict-peer-dependencies

- name: Build
run: pnpm run build

- uses: actions/upload-artifact@v3
with:
name: astro-cookieconsent
path: dist
23 changes: 23 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "CI - Pipeline 🚀"

on:
push:
branches:
- "main"
pull_request:
workflow_dispatch:
inputs:
workflow:
description: "Workflow to run"
required: true
default: "lint"

jobs:

lint:
uses: "./.github/workflows/lint.yaml"

build:
needs:
- lint
uses: "./.github/workflows/build.yaml"
45 changes: 45 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: "Lint 🧹"

on:
workflow_call:

jobs:
lint:
name: "Lint"
runs-on: ubuntu-latest

steps:
- name: "Checkout"
uses: actions/checkout@v3

- name: "Setup NodeJS"
uses: actions/setup-node@v3
with:
node-version: "18"

- uses: pnpm/action-setup@v2
name: Install pnpm
id: pnpm-install
with:
version: 7
run_install: false

- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --strict-peer-dependencies

- name: Build
run: pnpm run build
69 changes: 69 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: "Publish 🚀"

on:
push:
tags:
- "v*"

jobs:
lint:
uses: "./.github/workflows/lint.yaml"

build:
uses: "./.github/workflows/build.yaml"

github-release:
name: "GitHub Release"
runs-on: ubuntu-latest
needs:
- lint
- build
steps:
- name: "Release 🚀"
uses: "softprops/action-gh-release@v1"
with:
generate_release_notes: true

publish-github:
name: "Publish to Github Packages"
needs:
- github-release
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/download-artifact@v3
with:
name: astro-cookieconsent
path: .

# Setup .npmrc file to publish to GitHub Packages
- uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: 'https://npm.pkg.github.com'

- run: pnpm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

publish-npm:
name: "Publish to NPM"
needs:
- github-release
runs-on: "ubuntu-latest"
steps:
- uses: actions/download-artifact@v3
with:
name: astro-cookieconsent
path: .

- uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: "https://registry.npmjs.org/"

- run: pnpm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
auto-install-peers=true
Empty file added .prettierrc.json
Empty file.
31 changes: 20 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import * as CookieConsent from "vanilla-cookieconsent";

const createPlugin = (config: UserConfig) => {
return {
name: "@jop-software/astro-cookie-consent",
hooks: {
"astro:config:setup": async ({ injectScript }: any) => {
injectScript("page", "import 'vanilla-cookieconsent'; import 'vanilla-cookieconsent/dist/cookieconsent.css';");
injectScript("page", `window.cookieConentConfiguration = ${JSON.stringify(config)}`);
injectScript("page", `window.cookieConent = initCookieConsent();`)
injectScript("page", `window.cookieConent.run(window.cookieConentConfiguration);`)
},
},
};
return {
name: "@jop-software/astro-cookie-consent",
hooks: {
"astro:config:setup": async ({ injectScript }: any) => {
injectScript(
"page",
"import 'vanilla-cookieconsent'; import 'vanilla-cookieconsent/dist/cookieconsent.css';"
);
injectScript(
"page",
`window.cookieConentConfiguration = ${JSON.stringify(config)}`
);
injectScript("page", `window.cookieConent = initCookieConsent();`);
injectScript(
"page",
`window.cookieConent.run(window.cookieConentConfiguration);`
);
},
},
};
};

export type { CookieConsent };
Expand Down

0 comments on commit f6d0f61

Please sign in to comment.