auto increment Version

This commit is contained in:
Kilian von Pflugk 2024-05-26 01:23:38 +02:00
parent 1973dee1f8
commit 68582ede98
2 changed files with 50 additions and 21 deletions

View File

@ -2,11 +2,6 @@ name: 'Release Plugin'
on: on:
workflow_dispatch: workflow_dispatch:
inputs:
version:
description: 'Version v'
required: true
type: string
permissions: permissions:
contents: write contents: write
@ -34,8 +29,6 @@ jobs:
- name: Run update version - name: Run update version
run: node update-version.js run: node update-version.js
env:
VERSION: ${{ github.event.inputs.version }}
- name: Embed version info - name: Embed version info
run: echo "${{ github.sha }}" > ConfusedPolarBear.Plugin.IntroSkipper/Configuration/version.txt run: echo "${{ github.sha }}" > ConfusedPolarBear.Plugin.IntroSkipper/Configuration/version.txt
@ -46,7 +39,7 @@ jobs:
- name: Upload artifact - name: Upload artifact
uses: actions/upload-artifact@v4.3.3 uses: actions/upload-artifact@v4.3.3
with: with:
name: ConfusedPolarBear.Plugin.IntroSkipper-v${{ github.event.inputs.version }}.dll name: ConfusedPolarBear.Plugin.IntroSkipper-v${{ env.NEW_FILE_VERSION }}.dll
path: ConfusedPolarBear.Plugin.IntroSkipper/bin/Debug/net8.0/ConfusedPolarBear.Plugin.IntroSkipper.dll path: ConfusedPolarBear.Plugin.IntroSkipper/bin/Debug/net8.0/ConfusedPolarBear.Plugin.IntroSkipper.dll
if-no-files-found: error if-no-files-found: error
@ -55,14 +48,14 @@ jobs:
with: with:
files: | files: |
ConfusedPolarBear.Plugin.IntroSkipper/bin/Debug/net8.0/ConfusedPolarBear.Plugin.IntroSkipper.dll ConfusedPolarBear.Plugin.IntroSkipper/bin/Debug/net8.0/ConfusedPolarBear.Plugin.IntroSkipper.dll
dest: intro-skipper-v${{ github.event.inputs.version }}.zip dest: intro-skipper-v${{ env.NEW_FILE_VERSION }}.zip
- name: Generate manifest keys - name: Generate manifest keys
run: | run: |
sourceUrl="https://github.com/${{ github.repository }}/releases/download/10.9/v${{ github.event.inputs.version }}/intro-skipper-v${{ github.event.inputs.version }}.zip" sourceUrl="https://github.com/${{ github.repository }}/releases/download/10.9/v${{ env.NEW_FILE_VERSION }}/intro-skipper-v${{ env.NEW_FILE_VERSION }}.zip"
echo "SOURCE_URL=$sourceUrl" >> $GITHUB_ENV echo "SOURCE_URL=$sourceUrl" >> $GITHUB_ENV
md5sum intro-skipper-v${{ github.event.inputs.version }}.zip > intro-skipper-v${{ github.event.inputs.version }}.md5 md5sum intro-skipper-v${{ env.NEW_FILE_VERSION }}.zip > intro-skipper-v${{ env.NEW_FILE_VERSION }}.md5
checksum="$(awk '{print $1}' intro-skipper-v${{ github.event.inputs.version }}.md5)" checksum="$(awk '{print $1}' intro-skipper-v${{ env.NEW_FILE_VERSION }}.md5)"
echo "CHECKSUM=$checksum" >> $GITHUB_ENV echo "CHECKSUM=$checksum" >> $GITHUB_ENV
timestamp="$(date +%FT%TZ)" timestamp="$(date +%FT%TZ)"
echo "TIMESTAMP=$timestamp" >> $GITHUB_ENV echo "TIMESTAMP=$timestamp" >> $GITHUB_ENV
@ -71,17 +64,17 @@ jobs:
uses: 8bitDream/action-github-releases@v1.0.0 uses: 8bitDream/action-github-releases@v1.0.0
with: with:
repo_token: "${{ secrets.GITHUB_TOKEN }}" repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: 10.9/v${{ github.event.inputs.version }} automatic_release_tag: 10.9/v${{ env.NEW_FILE_VERSION }}
prerelease: false prerelease: false
title: v${{ github.event.inputs.version }} title: v${{ env.NEW_FILE_VERSION }}
files: | files: |
intro-skipper-v${{ github.event.inputs.version }}.zip intro-skipper-v${{ env.NEW_FILE_VERSION }}.zip
- name: Publish release notes - name: Publish release notes
uses: softprops/action-gh-release@v2.0.5 uses: softprops/action-gh-release@v2.0.5
with: with:
tag_name: 10.9/v${{ github.event.inputs.version }} tag_name: 10.9/v${{ env.NEW_FILE_VERSION }}
name: v${{ github.event.inputs.version }} name: v${{ env.NEW_FILE_VERSION }}
draft: false draft: false
prerelease: false prerelease: false
env: env:
@ -90,7 +83,7 @@ jobs:
- name: Run validation and update script - name: Run validation and update script
run: node validate-and-update-manifest.js run: node validate-and-update-manifest.js
env: env:
VERSION: ${{ github.event.inputs.version }} VERSION: ${{ env.NEW_FILE_VERSION }}
- name: Commit changes - name: Commit changes
if: success() if: success()
@ -98,5 +91,5 @@ jobs:
git config --global user.name "github-actions[bot]" git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com" git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add manifest.json ConfusedPolarBear.Plugin.IntroSkipper/ConfusedPolarBear.Plugin.IntroSkipper.csproj git add manifest.json ConfusedPolarBear.Plugin.IntroSkipper/ConfusedPolarBear.Plugin.IntroSkipper.csproj
git commit -m "release v${{ github.event.inputs.version }}" git commit -m "release v${{ env.NEW_FILE_VERSION }}"
git push git push

View File

@ -8,7 +8,7 @@ if (!fs.existsSync(csprojPath)) {
} }
function updateCsprojVersion() { function updateCsprojVersion() {
const newVersion = process.env.VERSION const newVersion = process.env.VERSION
const csprojContent = fs.readFileSync(csprojPath, 'utf8'); const csprojContent = fs.readFileSync(csprojPath, 'utf8');
const updatedContent = csprojContent const updatedContent = csprojContent
@ -19,4 +19,40 @@ function updateCsprojVersion() {
console.log('Updated .csproj file with new version.'); console.log('Updated .csproj file with new version.');
} }
updateCsprojVersion() // Function to increment version string
function incrementVersion(version) {
const parts = version.split('.').map(Number);
parts[parts.length - 1] += 1; // Increment the last part of the version
return parts.join('.');
}
// Read the .csproj file
fs.readFile(csprojPath, 'utf8', (err, data) => {
if (err) {
return console.error('Failed to read .csproj file:', err);
}
let newAssemblyVersion = null;
let newFileVersion = null;
// Use regex to find and increment versions
const updatedData = data.replace(/<AssemblyVersion>(.*?)<\/AssemblyVersion>/, (match, version) => {
newAssemblyVersion = incrementVersion(version);
return `<AssemblyVersion>${newAssemblyVersion}</AssemblyVersion>`;
}).replace(/<FileVersion>(.*?)<\/FileVersion>/, (match, version) => {
newFileVersion = incrementVersion(version);
return `<FileVersion>${newFileVersion}</FileVersion>`;
});
// Write the updated XML back to the .csproj file
fs.writeFile(csprojPath, updatedData, 'utf8', (err) => {
if (err) {
return console.error('Failed to write .csproj file:', err);
}
console.log('Version incremented successfully!');
// Write the new versions to GitHub Actions environment files
fs.appendFileSync(process.env.GITHUB_ENV, `NEW_ASSEMBLY_VERSION=${newAssemblyVersion}\n`);
fs.appendFileSync(process.env.GITHUB_ENV, `NEW_FILE_VERSION=${newFileVersion}\n`);
});
});