Skip to content

Create update for SuperBLT mod via version change #12

Create update for SuperBLT mod via version change

Create update for SuperBLT mod via version change #12

name: Create update for SuperBLT mod via version change
permissions:
contents: write
on:
workflow_dispatch:
inputs:
branch:
description: "What branch should this action use?"
required: true
type: string
default: "main"
mod_new_version:
description: 'New version value. Will be used as tag'
required: true
type: string
mod_txt_path:
description: 'Releative path to mod.txt from root dir'
required: true
type: string
default: "mod.txt"
meta_json_path:
description: 'Releative path to meta.json from root dir'
required: true
type: string
default: "meta.json"
filename_release:
description: 'What filename should be used for release artifact. If omitted, action will use "%OWNER%.%REPO%" format'
type: string
release_title:
description: 'Title for release. Will be used in format "%RELEASE_TITLE% %RELEASE_TITLE_VERSION%"'
required: true
type: string
default: "Update"
release_title_version:
description: 'Mod version for title, if omitted it will fallback to tag name. Will be used in format "%RELEASE_TITLE% %RELEASE_TITLE_VERSION%"'
type: string
should_action_replace_download_url:
description: "Should action change download url to latest/tag release or don't change it?"
type: choice
options:
- tag
- latest
- nochange
should_replace_patchnotes:
description: "Should action change patchnotes url to latest/tag release or don't change it?"
type: choice
options:
- tag
- latest
- nochange
jobs:
create-update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.branch }}
- name: Determine version for release
uses: haya14busa/action-cond@v1
id: version_for_release
with:
cond: ${{ github.event.inputs.release_title_version != '' }}
if_true: ${{ github.event.inputs.release_title_version }}
if_false: ${{ github.event.inputs.mod_new_version }}
- name: Determine patchnotes url based on input
if: ${{ inputs.should_replace_patchnotes != 'nochange' }}
uses: haya14busa/action-cond@v1
id: patchnotes_url
with:
cond: ${{ github.event.inputs.should_replace_patchnotes == 'tag' }}
if_true: https://github.com/${{ github.repository }}/releases/tag/${{ inputs.mod_new_version }}
if_false: https://github.com/${{ github.repository }}/releases/latest
- name: Determine filename based on input
uses: haya14busa/action-cond@v1
id: release_filename
with:
cond: ${{ github.event.inputs.filename_release == '' }}
if_true: ${{ github.repository_owner }}.${{ github.event.repository.name }}.zip
if_false: ${{ github.event.inputs.filename_release }}.zip
- name: Determine to what change download_url
if: ${{ inputs.should_action_replace_download_url != 'nochange' }}
uses: haya14busa/action-cond@v1
id: new_download_url
with:
cond: ${{ github.event.inputs.should_action_replace_download_url == 'tag' }}
if_true: https://github.com/${{ github.repository }}/releases/download/${{ inputs.mod_new_version }}/${{ steps.release_filename.outputs.value }}
# Why GitHub? Why for latest release its /latest/download, but for tag is /download/tag?
if_false: https://github.com/${{ github.repository }}/releases/latest/download/${{ steps.release_filename.outputs.value }}
- name: Replace version in mod.txt
run: |
echo "Replacing version in mod.txt"
perl -pe 's/(?<="version")\s*:\s*".*"/: "${{ inputs.mod_new_version }}"/g' ${{ inputs.mod_txt_path }} > new_mod.txt
mv new_mod.txt ${{ inputs.mod_txt_path }}
- name: Replace version in meta.json
run: |
echo "Replacing version in meta.json"
perl -pe 's/(?<="version")\s*:\s*".*"/: "${{ inputs.mod_new_version }}"/g' ${{ inputs.meta_json_path }} > new_meta.json
mv new_meta.json ${{ inputs.meta_json_path }}
- name: Replace patchnotes url in meta.json
if: ${{ inputs.should_replace_patchnotes != 'nochange' }}
run: |
echo "Replacing patchnotes url in meta.json"
echo "New patchnotes url is ${{ steps.patchnotes_url.outputs.value }}"
perl -pe 's#(?<="patchnotes_url")\s*:\s*".*"#: "${{ steps.patchnotes_url.outputs.value }}"#g' ${{ inputs.meta_json_path }} > new_meta.json
mv new_meta.json ${{ inputs.meta_json_path }}
- name: Replace download_url in meta.json
if: ${{ inputs.should_action_replace_download_url != 'nochange' }}
run: |
echo "Replacing download_url in meta.json"
echo "New url is ${{ steps.new_download_url.outputs.value }}"
echo "Release filename is ${{ steps.release_filename.outputs.value }}"
perl -pe 's#(?<="download_url")\s*:\s*".*"#: "${{ steps.new_download_url.outputs.value }}"#g' ${{ inputs.meta_json_path }} > new_meta.json
mv new_meta.json ${{ inputs.meta_json_path }}
- name: Setup github actions account
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "GitHub Actions"
- name: Push new meta.json and meta.json
run: |
git add ${{ inputs.meta_json_path }}
git add ${{ inputs.mod_txt_path }}
git commit -m "Updated version in meta.json and mod.txt" || echo "Ignore commit failure, proceed. Error code: $?"
git push
- name: Change flag to pushed
run: echo "IS_PUSHED=true" >> $GITHUB_ENV
- name: Create release notes
uses: johnyherangi/create-release-notes@main
id: create-release-notes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create archive for release
uses: thedoctor0/[email protected]
with:
type: 'zip'
filename: ${{ steps.release_filename.outputs.value }}
exclusions: '*.git* .github/**/*.*'
- name: Create release
uses: ncipollo/release-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
artifacts: ${{ steps.release_filename.outputs.value }}
tag: ${{ inputs.mod_new_version }}
name: ${{ github.event.inputs.release_title }} ${{ steps.version_for_release.outputs.value }}
body: ${{ steps.create-release-notes.outputs.release-notes }}
- name: Revert commits on failure
if: ${{ failure() && env.IS_PUSHED }}
run: |
git revert $(git rev-parse HEAD)
git push