diff --git a/.github/actions/bump-manifest-version.js b/.github/actions/bump-manifest-version.js index 5fe3462..fe359b1 100644 --- a/.github/actions/bump-manifest-version.js +++ b/.github/actions/bump-manifest-version.js @@ -1,10 +1,8 @@ -const fs = require('fs'); +const fxManifest = await Bun.file('./fxmanifest.lua').text(); -const version = process.env.TGT_RELEASE_VERSION; -const newVersion = version.replace('v', ''); +let newVersion = process.env.TGT_RELEASE_VERSION; +newVersion = newVersion.replace('v', '') -const manifestFile = fs.readFileSync('fxmanifest.lua', { encoding: 'utf8' }); +const newFileContent = fxManifest.replace(/\bversion\s+(.*)$/gm, `version '${newVersion}'`); -const newFileContent = manifestFile.replace(/\bversion\s+(.*)$/gm, `version '${newVersion}'`); - -fs.writeFileSync('fxmanifest.lua', newFileContent); +await Bun.write('./fxmanifest.lua', newFileContent); diff --git a/.github/actions/bump-package-version.js b/.github/actions/bump-package-version.js index 31577a0..c1e5ddd 100644 --- a/.github/actions/bump-package-version.js +++ b/.github/actions/bump-package-version.js @@ -1,10 +1,6 @@ -const fs = require('fs'); +const packageJson = await Bun.file('./package/package.json').json(); -const version = process.env.TGT_RELEASE_VERSION; -const newVersion = version.replace('v', ''); +const newVersion = process.env.TGT_RELEASE_VERSION; +packageJson.version = newVersion.replace('v', ''); -const packageFile = fs.readFileSync('package/package.json', { encoding: 'utf8' }); - -const newFileContent = packageFile.replace(/"version":\s+"(.*)",$/gm, `"version": "${newVersion}",`); - -fs.writeFileSync('package/package.json', newFileContent); +await Bun.write('./package/package.json', JSON.stringify(packageJson, null, 2)); diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7fbb673..54f439d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,26 +7,39 @@ on: jobs: create-release: + if: github.actor_id != 210085057 runs-on: ubuntu-latest steps: - - name: Get latest code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - ref: ${{ github.event.repository.default_branch }} + - name: Install zip + run: sudo apt install zip - - name: Setup Bun + - name: Install Bun uses: oven-sh/setup-bun@v2 with: bun-version: latest + - name: Generate GitHub App token + id: app_token + uses: tibdex/github-app-token@v2 + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} + + - name: Get latest code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.event.repository.default_branch }} + token: ${{ steps.app_token.outputs.token }} + + - name: Install package dependencies - run: bun install + run: bun install --frozen-lockfile working-directory: package - name: Install web dependencies - run: bun install + run: bun install --frozen-lockfile working-directory: web - name: Run web build script @@ -35,16 +48,15 @@ jobs: - name: Bump package version - run: bun .github/actions/bump-package-version.js + run: bun run .github/actions/bump-package-version.js env: TGT_RELEASE_VERSION: ${{ github.ref_name }} - name: Bump manifest version - run: bun .github/actions/bump-manifest-version.js + run: bun run .github/actions/bump-manifest-version.js env: TGT_RELEASE_VERSION: ${{ github.ref_name }} - - name: Push version bump change uses: EndBug/add-and-commit@v9 with: @@ -53,25 +65,10 @@ jobs: default_author: github_actions message: 'chore: bump version to ${{ github.ref_name }}' - - name: Update tag - uses: EndBug/latest-tag@v1 - with: - ref: ${{ github.ref_name }} - - - - name: Publish package to npm registry - run: bun publish --access public - working-directory: package - env: - NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }} - - - name: Install zip - run: sudo apt install zip - name: Bundle files run: | - mkdir -p ./temp/ox_lib - mkdir -p ./temp/ox_lib/web/ + mkdir -p ./temp/ox_lib/web cp ./{LICENSE,README.md,fxmanifest.lua,init.lua} ./temp/ox_lib cp -r ./{imports,resource,locales} ./temp/ox_lib cp -r ./web/build ./temp/ox_lib/web/ @@ -79,11 +76,18 @@ jobs: - name: Create release uses: 'marvinpinto/action-automatic-releases@v1.2.1' - id: auto_release with: repo_token: ${{ secrets.GITHUB_TOKEN }} prerelease: false files: ox_lib.zip + + - name: Update tag + uses: EndBug/latest-tag@v1 + with: + ref: ${{ github.ref_name }} + + - name: Publish package to npm registry + run: bun publish --access public + working-directory: package env: - CI: false - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}