Skip to content

Commit

Permalink
Merge pull request #7 from cewert/create-version-bump-workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
cewert authored Feb 10, 2024
2 parents 8d7ccdf + baa2a26 commit 9760253
Showing 1 changed file with 168 additions and 0 deletions.
168 changes: 168 additions & 0 deletions .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
name: "Create PR to bump version"

on:
workflow_dispatch:
branches:
- master
- "*.*.z"
inputs:
versionType:
description: 'Version to Bump'
required: true
type: choice
options:
- build
- minor
- major

jobs:
build:
if: ${{ github.event.inputs.versionType }} == 'build'
runs-on: ubuntu-latest
steps:
# Setup
- name: Checkout code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- name: Install jq to manipulate json
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: jq
- name: Save a copy of github.ref_name without periods to env var
run: echo "refNameSlug=${{ github.ref_name }}" | sed -e 's/\.//g'
# Save old version
- name: Find and save old major_version from manifest
run: awk 'BEGIN { FS="=" } /^major_version/ { print "oldMajor="$2; }' manifest >> $GITHUB_ENV
- name: Find and save old minor_version from manifest
run: awk 'BEGIN { FS="=" } /^minor_version/ { print "oldMinor="$2; }' manifest >> $GITHUB_ENV
- name: Find and save old build_version from manifest
run: awk 'BEGIN { FS="=" } /^build_version/ { print "oldBuild="$2; }' manifest >> $GITHUB_ENV
# Calculate new version
- name: Calculate new build_version
run: echo "newBuild=$((${{ env.oldBuild }} + 1))" >> $GITHUB_ENV
- name: Save new version to env var
run: echo "newVersion=${{ env.oldMajor }}.${{ env.oldMinor }}.${{ env.newBuild }}" >> $GITHUB_ENV
- name: Save a copy of newVersion without periods to env var
run: echo "newVersionSlug=${{ env.newVersion }}" | sed -e 's/\.//g'
# Update files with new versions
- name: Update manifest build_version
run: sed -i "s/build_version=.*/build_version=${{ env.newBuild }}/g" manifest
- name: Update package-lock.json version
run: echo "$( jq '.version = "'"${{ env.newVersion }}"'"' package-lock.json )" > package-lock.json
- name: Update package-lock.json version 2
run: echo "$( jq '.packages."".version = "'"${{ env.newVersion }}"'"' package-lock.json )" > package-lock.json
- name: Update package.json version
run: echo "$( jq '.version = "'"${{ env.newVersion }}"'"' package.json )" > package.json
- name: Update Makefile version
run: sed -i "s/VERSION := .*/VERSION := ${{ env.newVersion }}/g" Makefile
# Create PR
- name: Create PR with new version
run: |-
git config user.name "jellyfin-bot"
git config user.email "[email protected]"
git checkout -b "bump-${{ env.refNameSlug }}-to-${{ env.newVersionSlug }}"
git add .
git commit -m "Bump ${{ github.event.inputs.versionType }} version"
gh pr create --base ${{ github.ref_name }} --head ${{ github.ref_name }} --fill
minor:
if: ${{ github.event.inputs.versionType }} == 'minor'
runs-on: ubuntu-latest
steps:
# Setup
- name: Checkout code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- name: Install jq to update json
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: jq
- name: Save a copy of github.ref_name without periods to env var
run: echo "refNameSlug=${{ github.ref_name }}" | sed -e 's/\.//g'
# Save old version
- name: Find and save old major_version from manifest
run: awk 'BEGIN { FS="=" } /^major_version/ { print "oldMajor="$2; }' manifest >> $GITHUB_ENV
- name: Find and save old minor_version from manifest
run: awk 'BEGIN { FS="=" } /^minor_version/ { print "oldMinor="$2; }' manifest >> $GITHUB_ENV
- name: Find and save old build_version from manifest
run: awk 'BEGIN { FS="=" } /^build_version/ { print "oldBuild="$2; }' manifest >> $GITHUB_ENV
# Calculate new version
- name: Calculate new build_version
run: echo "newMinor=$((${{ env.oldMinor }} + 1))" >> $GITHUB_ENV
- name: Save new version to env var
run: echo "newVersion=${{ env.oldMajor }}.${{ env.newMinor }}.0" >> $GITHUB_ENV
- name: Save a copy of newVersion without periods to env var
run: echo "newVersionSlug=${{ env.newVersion }}" | sed -e 's/\.//g'
# Update files with new versions
- name: Update manifest minor_version
run: sed -i "s/minor_version=.*/minor_version=${{ env.newMinor }}/g" manifest
- name: Update manifest build_version
run: sed -i "s/build_version=.*/build_version=0/g" manifest
- name: Update package-lock.json version
run: echo "$( jq '.version = "'"${{ env.newVersion }}"'"' package-lock.json )" > package-lock.json
- name: Update package-lock.json version 2
run: echo "$( jq '.packages."".version = "'"${{ env.newVersion }}"'"' package-lock.json )" > package-lock.json
- name: Update package.json version
run: echo "$( jq '.version = "'"${{ env.newVersion }}"'"' package.json )" > package.json
- name: Update Makefile version
run: sed -i "s/VERSION := .*/VERSION := ${{ env.newVersion }}/g" Makefile
# Create PR
- name: Create PR with new version
run: |-
git config user.name "jellyfin-bot"
git config user.email "[email protected]"
git checkout -b "bump-${{ env.refNameSlug }}-to-${{ env.newVersionSlug }}"
git add .
git commit -m "Bump ${{ github.event.inputs.versionType }} version"
gh pr create --base ${{ github.ref_name }} --head ${{ github.ref_name }} --fill
major:
if: ${{ github.event.inputs.versionType }} == 'major'
runs-on: ubuntu-latest
steps:
# Setup
- name: Checkout code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- name: Install jq to update json
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: jq
- name: Save a copy of github.ref_name without periods to env var
run: echo "refNameSlug=${{ github.ref_name }}" | sed -e 's/\.//g'
# Save old version
- name: Find and save old major_version from manifest
run: awk 'BEGIN { FS="=" } /^major_version/ { print "oldMajor="$2; }' manifest >> $GITHUB_ENV
- name: Find and save old minor_version from manifest
run: awk 'BEGIN { FS="=" } /^minor_version/ { print "oldMinor="$2; }' manifest >> $GITHUB_ENV
- name: Find and save old build_version from manifest
run: awk 'BEGIN { FS="=" } /^build_version/ { print "oldBuild="$2; }' manifest >> $GITHUB_ENV
# Calculate new version
- name: Calculate new build_version
run: echo "newMajor=$((${{ env.oldMajor }} + 1))" >> $GITHUB_ENV
- name: Save new version to env var
run: echo "newVersion=${{ env.newMajor }}.0.0" >> $GITHUB_ENV
- name: Save a copy of newVersion without periods to env var
run: echo "newVersionSlug=${{ env.newVersion }}" | sed -e 's/\.//g'
# Update files with new versions
- name: Update manifest major_version
run: sed -i "s/major_version=.*/major_version=${{ env.newMajor }}/g" manifest
- name: Update manifest minor_version
run: sed -i "s/minor_version=.*/minor_version=0/g" manifest
- name: Update manifest build_version
run: sed -i "s/build_version=.*/build_version=0/g" manifest
- name: Update package-lock.json version
run: echo "$( jq '.version = "'"${{ env.newVersion }}"'"' package-lock.json )" > package-lock.json
- name: Update package-lock.json version 2
run: echo "$( jq '.packages."".version = "'"${{ env.newVersion }}"'"' package-lock.json )" > package-lock.json
- name: Update package.json version
run: echo "$( jq '.version = "'"${{ env.newVersion }}"'"' package.json )" > package.json
- name: Update Makefile version
run: sed -i "s/VERSION := .*/VERSION := ${{ env.newVersion }}/g" Makefile
# Create PR
- name: Create PR with new version
run: |-
git config user.name "jellyfin-bot"
git config user.email "[email protected]"
git checkout -b "bump-${{ env.refNameSlug }}-to-${{ env.newVersionSlug }}"
git add .
git commit -m "Bump ${{ github.event.inputs.versionType }} version"
gh pr create --base ${{ github.ref_name }} --head ${{ github.ref_name }} --fill

0 comments on commit 9760253

Please sign in to comment.