From 37eb6a2002f40a1f7a1969aefe24ad3519d63ca6 Mon Sep 17 00:00:00 2001 From: Manason Date: Mon, 9 Sep 2024 08:14:31 -0700 Subject: [PATCH] chore(github): create release and lint actions --- .github/actions/bump-manifest-version.js | 11 +++++ .github/workflows/lint.yml | 23 ++++++++++ .github/workflows/release-action.yml | 55 ++++++++++++++++++++++++ .github/workflows/release.yml | 35 +++++++++++++++ 4 files changed, 124 insertions(+) create mode 100644 .github/actions/bump-manifest-version.js create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/release-action.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/actions/bump-manifest-version.js b/.github/actions/bump-manifest-version.js new file mode 100644 index 0000000..3ce3ede --- /dev/null +++ b/.github/actions/bump-manifest-version.js @@ -0,0 +1,11 @@ +// Based off of https://github.com/overextended/ox_lib/blob/master/.github/actions/bump-manifest-version.js +const fs = require('fs') + +const version = process.env.TGT_RELEASE_VERSION +const newVersion = version.replace('v', '') + +const manifestFile = fs.readFileSync('fxmanifest.lua', {encoding: 'utf8'}) + +const newFileContent = manifestFile.replace(/\bversion\s+(.*)$/gm, `version '${newVersion}'`) + +fs.writeFileSync('fxmanifest.lua', newFileContent) \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..639bd54 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,23 @@ +name: Lint +on: [push, pull_request_target] +jobs: + lint: + name: Lint Resource + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: Lint + uses: iLLeniumStudios/fivem-lua-lint-action@v2 + with: + capture: "junit.xml" + args: "-t --formatter JUnit" + extra_libs: ox_lib+mysql+qblocales+qbox+qbox_playerdata+qbox_lib + - name: Generate Lint Report + if: always() + uses: mikepenz/action-junit-report@v4 + with: + report_paths: "**/junit.xml" + check_name: Linting Report + fail_on_failure: false \ No newline at end of file diff --git a/.github/workflows/release-action.yml b/.github/workflows/release-action.yml new file mode 100644 index 0000000..71524ae --- /dev/null +++ b/.github/workflows/release-action.yml @@ -0,0 +1,55 @@ +name: "Release Action" + +on: + workflow_run: + workflows: [Create New Release] + types: + - completed + +jobs: + release-action: + name: "Create Release" + runs-on: "ubuntu-latest" + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.event.repository.default_branch }} + + - name: Get the latest tag + id: get_tag + run: | + echo "LATEST_TAG=$(git tag --sort=-creatordate | head -n 1)" >> $GITHUB_ENV + + - name: Install ZIP + run: sudo apt install zip + + - name: Bundle files + run: | + shopt -s extglob + mkdir -p ./temp/${{ github.event.repository.name }} + cp ./{README.md,fxmanifest.lua} ./temp/${{ github.event.repository.name }} + cp -r ./{client,bridge,configs,modules,servers} ./temp/${{ github.event.repository.name }} + cd ./temp && zip -r ../${{ github.event.repository.name }}.zip ./${{ github.event.repository.name }} + + - name: Update CHANGELOG + id: changelog + uses: requarks/changelog-action@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + tag: ${{ env.LATEST_TAG }} + includeInvalidCommits: true + writeToFile: false + + - name: Create Release + uses: ncipollo/release-action@v1.14.0 + with: + allowUpdates: true + draft: false + makeLatest: true + name: ${{ env.LATEST_TAG }} + tag: ${{ env.LATEST_TAG }} + body: ${{ steps.changelog.outputs.changes }} + artifacts: ${{ github.event.repository.name }}.zip + token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..1c0424e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,35 @@ +name: Create New Release + +on: + workflow_dispatch: + inputs: + version: + required: true + +jobs: + create-release: + name: Create New Release + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version: 20.x + + - name: Bump manifest version + run: node .github/actions/bump-manifest-version.js + env: + TGT_RELEASE_VERSION: ${{ inputs.version }} + + - name: Push manifest change + uses: EndBug/add-and-commit@v9 + with: + add: fxmanifest.lua + push: true + message: 'chore: bump manifest version to ${{ inputs.version }}' + tag: ${{ inputs.version }} \ No newline at end of file