diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml new file mode 100644 index 00000000000000..ff35c872d23126 --- /dev/null +++ b/.github/workflows/prerelease.yml @@ -0,0 +1,81 @@ +name: Publish @mdn/browser-compat-data@next + +on: + push: + branches: + - main + +concurrency: + group: ${{ github.workflow }} +permissions: + contents: write + +env: + package: "@mdn/browser-compat-data" + tag: "next" + +jobs: + publish: + if: github.repository == 'mdn/browser-compat-data' + name: Publish next pre-release + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + ref: main + + - name: Setup Node + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 + with: + node-version-file: .nvmrc + cache: npm + package-manager-cache: true + + - name: Install + run: npm ci + + - name: Build + run: npm run build + + - name: Get short hash + id: hash + run: echo "SHORT_HASH=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT" + + - name: Ensure `next` pre-release exists + env: + GH_TOKEN: ${{ github.token }} + run: | + if ! gh release view "$tag" >/dev/null 2>&1; then + gh release create "$tag" \ + --title "$package@$tag" \ + --notes "Bootstrapping next pre-release." \ + --prerelease + fi + + - name: Draft existing release while we move the tag + env: + GH_TOKEN: ${{ github.token }} + run: gh release edit --draft "$tag" + + - name: Move the `next` tag + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git tag --force "$tag" + git push --force origin "$tag" + + - name: Publish the pre-release + env: + GH_TOKEN: ${{ github.token }} + SHORT_HASH: ${{ steps.hash.outputs.SHORT_HASH }} + NOTES: "This is a continuously-updated prerelease generated from `main` (currently at ${{ steps.hash.outputs.SHORT_HASH }})." + run: | + gh release edit \ + --verify-tag \ + --title "$package@$tag" \ + --notes "$NOTES" \ + --prerelease \ + --draft=false \ + "$tag" + gh release upload --clobber "$tag" build/data.json