Skip to content

Commit

Permalink
Merge pull request #1 from clFaster/feature/github-workflow
Browse files Browse the repository at this point in the history
feat: add workflow to build extension artifact
  • Loading branch information
clFaster authored Dec 21, 2024
2 parents b2a7b80 + 5c26483 commit 1308de8
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 3 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: "Build TapToQR Artifact"

on:
workflow_dispatch:
inputs:
VERSION:
description: "The version of the addon to build"
type: string
required: false

workflow_call:
inputs:
VERSION:
description: "The version of the addon to build"
type: string
required: false
push:
branches:
- main

pull_request:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && 'pull_request' || 'push' }}-${{ github.event.pull_request.number || github.ref_name }}
cancel-in-progress: true

jobs:
build-artifact:
name: "Build TapToQR Artifact"
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'

- name: Determine VERSION
id: determine-version
run: |
if [ -z "${{ inputs.VERSION }}" ]; then
echo "Using repository version"
echo ${{ vars.VERSION }}
echo "VERSION=${{ vars.VERSION }}" >> $GITHUB_OUTPUT
else
echo "Using input version"
echo ${{ inputs.VERSION }}
echo "VERSION=${{ inputs.VERSION }}" >> $GITHUB_OUTPUT
fi
- name: Update Version
run: |
jq --arg version "${{steps.determine-version.outputs.VERSION}}" '.version = $version' package.json > temp.json && mv temp.json package.json
cd addon
jq --arg version "${{steps.determine-version.outputs.VERSION}}" '.version = $version' manifest.json > temp.json && mv temp.json manifest.json
- name: Install dependencies
run: npm install

- name: Lint code
run: npm run lint

- name: Webpack project
run: npm run webpack-prod

- name: Create Artifact
run: |
cd addon
zip -r ../TapToQR-${{steps.determine-version.outputs.VERSION}}.zip ./*
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
path: 'TapToQR-${{steps.determine-version.outputs.VERSION}}.zip'
name: 'TapToQR-addon'
87 changes: 87 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: "Release TapToQR"

on:
workflow_dispatch:
inputs:
release-type:
type: choice
description: Which type of release to create?
required: true
default: patch
options:
- patch
- minor
- major

concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false

jobs:
# Get the Current Version and Bump it depending on the release-type input
update-version:
runs-on: ubuntu-latest
permissions: write-all
outputs:
new_version: ${{ steps.bump_version.outputs.new_version }}
steps:
- name: Ensure branch is main
if: github.ref != 'refs/heads/main'
run: |
text="Publish a new version can only be done from the main branch."
echo "::error title=Wrong Branch::$text"
exit 1
- name: Read current version
run: |
echo "Current version: ${{ vars.VERSION }}"
- name: Bump version
id: bump_version
run: |
# Retrieve the increment type from the GitHub Actions input
increment="${{ inputs.release-type }}"
# Split the VERSION variable into its major, minor, and patch components
IFS='.' read -r -a parts <<< "${{ vars.VERSION }}"
# Check if the VERSION variable was split correctly
if [ "${#parts[@]}" -ne 3 ]; then
echo "Invalid version format"
exit 1
fi
major=${parts[0]}
minor=${parts[1]}
patch=${parts[2]}
# Increment the appropriate version component
if [ "$increment" = "major" ]; then
major=$((major + 1))
minor=0
patch=0
elif [ "$increment" = "minor" ]; then
minor=$((minor + 1))
patch=0
elif [ "$increment" = "patch" ]; then
patch=$((patch + 1))
else
echo "Invalid increment type"
exit 1
fi
# Construct the new version string
new_version="$major.$minor.$patch"
# Output the new version
echo "New version: $new_version"
# Set the output variable for GitHub Actions
echo "new_version=$new_version" >> $GITHUB_OUTPUT
- name: Update version var
id: write_version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh variable set VERSION --body "${{ steps.bump_version.outputs.new_version }}"
5 changes: 2 additions & 3 deletions addon/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
"matches": ["<all_urls>"]
}
],

"content_security_policy": {
"extension_pages": "script-src 'self'; object-src 'self';"
},

"action": {
"default_popup": "popup/tap-to-qr.html",
"default_area": "navbar"
Expand All @@ -40,5 +40,4 @@
"id": "[email protected]"
}
}

}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Instantly generate and share a QR code for the webpage you're currently viewing, making link sharing seamless and quick.",
"scripts": {
"build": "webpack --config prod.webpack.config.js",
"webpack-prod": "webpack --config prod.webpack.config.js",
"lint": "cd addon && web-ext lint",
"dev": "webpack --config prod.webpack.config.js && cd addon && web-ext run --start-url https://mozilla.org --browser-console"
},
Expand Down

0 comments on commit 1308de8

Please sign in to comment.