Skip to content

Merge pull request #42 from Torehirth/15-create-light-mode #61

Merge pull request #42 from Torehirth/15-create-light-mode

Merge pull request #42 from Torehirth/15-create-light-mode #61

Workflow file for this run

# This GitHub Actions workflow is designed to:
#
# 1. Trigger on both `push` and `pull_request` events targeting the `main` branch.
#
# 2. On `push` to `main`:
# - The workflow uploads the project files as an artifact.
# - The deployment job runs, deploying the files to GitHub Pages.
# - The release job increments the patch version, creates a new Git tag, and pushes a release to GitHub.
#
# 3. On `pull_request`:
# - The workflow runs the same checks but does not perform deployment or release creation.
#
# 4. Permissions:
# - The necessary permissions (`id-token`, `contents`, `pages`) are granted for deploying to GitHub Pages, pushing tags, and creating releases.
# The workflow ensures that deployments and version tagging only happen after a successful merge into `main`,
# and it can perform testing and code quality checks during the pull request process.
name: Deploy and Auto-Increment Release
# Add necessary permissions for GitHub Pages deployment and creating releases
permissions:
id-token: write # Required for GitHub Pages deployment
contents: write # Required for pushing new tags and creating releases
pages: write # Required for deploying to GitHub Pages
actions: read # To read GitHub Actions workflow information
on:
push:
branches:
- main # Run on pushes to the main branch
pull_request:
branches:
- main # Run on pull requests into the main branch
jobs:
build:
# Only deploy on push events, not pull requests
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
# Upload the build output as an artifact
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
with:
path: ./ # Path to build output directory
# Deployment job
deploy:
# Only deploy on push events, not pull requests
if: github.event_name == 'push'
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
release:
# Only create a release on push events, not pull requests
if: github.event_name == 'push'
runs-on: ubuntu-latest
needs: deploy
steps:
- name: Checkout the code
uses: actions/checkout@v3
# Fetch all tags from the repository
- name: Fetch all tags
run: git fetch --tags
# Get the latest release tag
- name: Get the latest release tag
id: get_tag
run: |
TAG=$(git describe --tags --abbrev=0 || echo "v1.0.0") # Default to v1.0.0 if no tag exists
echo "::set-output name=TAG::$TAG"
# Increment the patch version
- name: Increment patch version
id: increment_version
run: |
TAG=${{ steps.get_tag.outputs.TAG }}
VERSION=${TAG#v}
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
PATCH=$((PATCH + 1))
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
echo "New version: v$NEW_VERSION"
echo "::set-output name=NEW_VERSION::v$NEW_VERSION"
# Create a new GitHub release
- name: Create Release
uses: actions/create-release@v1
with:
tag_name: ${{ steps.increment_version.outputs.NEW_VERSION }}
release_name: "Release ${{ steps.increment_version.outputs.NEW_VERSION }}"
body: "Deployment of version ${{ steps.increment_version.outputs.NEW_VERSION }}"
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Push the new tag to GitHub
- name: Push new tag
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git tag ${{ steps.increment_version.outputs.NEW_VERSION }}
git push origin ${{ steps.increment_version.outputs.NEW_VERSION }}