diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..c3db5a3 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,81 @@ +name: Release + +on: + push: + branches: + - master + +jobs: + release: + runs-on: ubuntu-latest + permissions: + contents: write + id-token: write + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install Node + uses: actions/setup-node@v4 + with: + node-version: '20.x' + registry-url: https://registry.npmjs.org + + - name: Install dependencies + run: npm ci + + - name: Run tests + run: npm test + + - name: Build package + run: npm run build + + - name: Read package version + id: pkg + run: echo "version=$(node -p \"require('./package.json').version\")" >> "$GITHUB_OUTPUT" + + - name: Check published version + id: published + run: | + PUBLISHED=$(npm view @wca/helpers version || echo "none") + echo "version=$PUBLISHED" >> "$GITHUB_OUTPUT" + + - name: Create tag from package version + id: create_tag + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const version = '${{ steps.pkg.outputs.version }}'; + const tag = `v${version}`; + const { owner, repo } = context.repo; + + try { + await github.rest.git.getRef({ owner, repo, ref: `tags/${tag}` }); + core.info(`Tag ${tag} already exists, skipping creation.`); + core.setOutput('created', 'false'); + return; + } catch (error) { + if (error.status !== 404) throw error; + } + + await github.rest.git.createRef({ + owner, + repo, + ref: `refs/tags/${tag}`, + sha: context.sha, + }); + core.info(`Created tag ${tag}.`); + core.setOutput('created', 'true'); + + - name: Publish to npm + if: steps.pkg.outputs.version != steps.published.outputs.version + run: npm publish --access public --provenance + + - name: Create GitHub release + if: steps.create_tag.outputs.created == 'true' + uses: softprops/action-gh-release@v1 + with: + tag_name: v${{ steps.pkg.outputs.version }} + generate_release_notes: true diff --git a/README.md b/README.md index 68e0804..a225107 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# WCA Helpers +\*\*\*\*# WCA Helpers > Helpers and class definitions for WCA and WCIF @@ -18,11 +18,18 @@ npm install @wca/helpers --save ## Development setup -## Meta +```sh +git clone +cd wca-helpers +npm install +npm run build +npm test +``` -Distributed under the GPL license. See `LICENSE` for more information. +## Release process -[https://github.com/thewca/wca-helpers](https://github.com/thewca/wca-helpers) +- Create a new PR bumping `package.json` version (and update `CHANGELOG.md` if needed). +- Merge the change to `master`; the `Release` GitHub Action will run tests/build, create a tag `v`, publish to npm, and generate a GitHub release. ## Contributing @@ -31,3 +38,9 @@ Distributed under the GPL license. See `LICENSE` for more information. 3. Commit your changes (`git commit -am 'Add some fooBar'`) 4. Push to the branch (`git push origin feature/fooBar`) 5. Create a new Pull Request + +## Meta + +Distributed under the GPL license. See `LICENSE` for more information. + +[https://github.com/thewca/wca-helpers](https://github.com/thewca/wca-helpers)