diff --git a/.github/workflows/draft_new_release.yml b/.github/workflows/draft_new_release.yml new file mode 100644 index 0000000..0e25309 --- /dev/null +++ b/.github/workflows/draft_new_release.yml @@ -0,0 +1,62 @@ +name: 'Draft new release' + +on: + workflow_dispatch: + inputs: + version: + description: 'The version you want to release.' + required: true + +jobs: + draft-new-release: + name: 'Draft a new release' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Create release branch + run: git checkout -b release/${{ github.event.inputs.version }} + + - name: Update changelog + uses: thomaseizinger/keep-a-changelog-new-release@1.1.0 + with: + version: ${{ github.event.inputs.version }} + + # In order to make a commit, we need to initialize a user. + - name: Initialize mandatory git config + run: | + git config user.name "GitHub Actions" + git config user.email noreply@github.com + + # This step will differ depending on your project setup + # Fortunately, yarn has a built-in command for doing this! + - name: Bump version in package.json + run: npm version ${{ github.event.inputs.version }} --no-git-tag-version + + - name: Commit changelog and manifest files + id: make-commit + run: | + git add CHANGELOG.md package.json + git commit --message "chore: prepare release ${{ github.event.inputs.version }}" + + echo "::set-output name=commit::$(git rev-parse HEAD)" + + - name: Push new branch + run: git push origin release/${{ github.event.inputs.version }} + + - name: Create pull request + uses: thomaseizinger/create-pull-request@1.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + head: release/${{ github.event.inputs.version }} + base: main + title: Release version ${{ github.event.inputs.version }} + reviewers: ${{ github.actor }} + body: | + Hi @${{ github.actor }}! + + This PR was created in response to a manual trigger of the release workflow here: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}. + I've updated the changelog and bumped the versions in the manifest files in this commit: ${{ steps.make-commit.outputs.commit }}. + + Merging this PR will create a GitHub release and upload any assets that are created as part of the release build. diff --git a/.github/workflows/publish_new_release.yml b/.github/workflows/publish_new_release.yml new file mode 100644 index 0000000..415cc95 --- /dev/null +++ b/.github/workflows/publish_new_release.yml @@ -0,0 +1,78 @@ +name: 'Publish new release' + +on: + pull_request: + branches: + - main + types: + - closed + +jobs: + release: + name: Publish new release + runs-on: ubuntu-latest + # only merged pull requests that begin with 'release/' or 'hotfix/' must trigger this job + if: github.event.pull_request.merged == true && + (startsWith(github.event.pull_request.head.ref, 'release/') || startsWith(github.event.pull_request.head.ref, 'hotfix/')) + + steps: + - name: Extract version from branch name (for release branches) + if: startsWith(github.event.pull_request.head.ref, 'release/') + run: | + BRANCH_NAME="${{ github.event.pull_request.head.ref }}" + VERSION=${BRANCH_NAME#release/} + + echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV + + - name: Extract version from branch name (for hotfix branches) + if: startsWith(github.event.pull_request.head.ref, 'hotfix/') + run: | + BRANCH_NAME="${{ github.event.pull_request.head.ref }}" + VERSION=${BRANCH_NAME#hotfix/} + + echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV + + - uses: actions/checkout@v3 + + - name: Use Node.js 18.x + uses: actions/setup-node@v3 + with: + node-version: 18.x + cache: 'npm' + + - name: Install Node modules + run: npm ci + + - name: Build scripts + run: npm run build-userscript + + - name: Extract release notes + id: extract-release-notes + uses: ffurrer2/extract-release-notes@v1 + with: + changelog_file: CHANGELOG.md + + - name: Release + uses: softprops/action-gh-release@v1 + with: + target_commitish: ${{ github.event.pull_request.merge_commit_sha }} + tag_name: ${{ env.RELEASE_VERSION }} + name: ${{ env.RELEASE_VERSION }} + draft: false + prerelease: false + body: ${{ steps.extract-release-notes.outputs.release_notes }} + files: | + ./dist/qc-ext.user.js + ./dist/qc-ext.meta.js + + - name: Merge main into dev branch + uses: thomaseizinger/create-pull-request@1.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + head: main + base: develop + title: Merge main into develop branch + body: | + This PR merges the main branch back into develop. + This happens to ensure that the updates that happend on the release branch, i.e. CHANGELOG and manifest updates are also present on the dev branch. diff --git a/CHANGELOG.md b/CHANGELOG.md index 8341ca5..03c0877 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased][unreleased] +## [Unreleased] > Hello! It has once again been a while, but this time, it's a big one! I've been meaning to do it for a long time, but I finally got around to rewrite the extension from scratch using React as the framework rather than AngularJS v1. While I was at it, I also updated/upgraded everything else about the script that I could, and it's much more modern and user friendly now. > diff --git a/build.js b/build.js index 0f95f5b..b80e30f 100644 --- a/build.js +++ b/build.js @@ -77,7 +77,24 @@ s.on('end', () => { s.pipe(w, { end: false }) s.on('end', () => { - fs.createReadStream('./build/static/js/main.js').pipe(w) + let mr = fs.createReadStream('./build/static/js/main.js') + mr.pipe(w) + mr.on('end', () => { + // Open the meta file for writing + let w = fs.createWriteStream('./dist/qc-ext.meta.js', { + flags: 'w', + }) + + let s = new Readable() + s._read = () => {} + s.push(licenseBanner) + s.push('\n') + s.push(productionUserscriptHeader) + s.push('\n') + s.push(null) + + s.pipe(w, { end: false }) + }) }) }) }) diff --git a/buildValues.js b/buildValues.js index 60cfd69..649bfe1 100644 --- a/buildValues.js +++ b/buildValues.js @@ -53,9 +53,7 @@ const userscriptHeader = `\ // @require <%=react-redux-js%> // @require <%=redux-logger-js%> // @require <%=redux-toolkit-js%> -// @connect questionablextensions.net -// @connect questionablecontent.herokuapp.com -// @connect localhost +// @connect <%=connect%> // @grant GM.openInTab // @grant GM.setValue // @grant GM.getValue @@ -74,6 +72,7 @@ const userscriptHeaderVariables = { description: 'Development mode for Questionable Content Extensions Script. ' + 'Loads the script directly from the last output of `npm start` on page refresh.', + connect: 'localhost', 'react-js': 'https://unpkg.com/react@17/umd/react.development.js', 'react-dom-js': 'https://unpkg.com/react-dom@17/umd/react-dom.development.js', @@ -88,6 +87,7 @@ const userscriptHeaderVariables = { description: 'Converts questionablecontent.net into a single-page application and adds ' + 'extra features, such as character, location and storyline navigation.', + connect: 'questionablextensions.net', 'react-js': 'https://unpkg.com/react@17/umd/react.production.min.js', 'react-dom-js': 'https://unpkg.com/react-dom@17/umd/react-dom.production.min.js',