|
| 1 | +name: Dev Draft Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["CI"] |
| 6 | + types: [completed] |
| 7 | + |
| 8 | +jobs: |
| 9 | + draft-release: |
| 10 | + name: Create/Update Dev Draft Release |
| 11 | + if: > |
| 12 | + github.event.workflow_run.conclusion == 'success' && |
| 13 | + github.event.workflow_run.event == 'push' && |
| 14 | + github.event.workflow_run.head_branch == 'dev' |
| 15 | + runs-on: ubuntu-latest |
| 16 | + permissions: |
| 17 | + contents: write |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout dev commit |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + ref: ${{ github.event.workflow_run.head_sha }} |
| 24 | + fetch-depth: 0 |
| 25 | + submodules: recursive |
| 26 | + |
| 27 | + - name: Compute dev tag |
| 28 | + id: tag |
| 29 | + run: | |
| 30 | + BASE_VERSION=$(node -p "require('./package.json').version") |
| 31 | + DEV_SUFFIX="dev.${{ github.event.workflow_run.run_number }}" |
| 32 | + DEV_TAG="v${BASE_VERSION}-${DEV_SUFFIX}" |
| 33 | + echo "base_version=${BASE_VERSION}" >> "$GITHUB_OUTPUT" |
| 34 | + echo "dev_tag=${DEV_TAG}" >> "$GITHUB_OUTPUT" |
| 35 | +
|
| 36 | + - name: Remove previous dev draft releases |
| 37 | + uses: actions/github-script@v7 |
| 38 | + with: |
| 39 | + script: | |
| 40 | + const releases = await github.paginate(github.rest.repos.listReleases, { |
| 41 | + owner: context.repo.owner, |
| 42 | + repo: context.repo.repo, |
| 43 | + per_page: 100, |
| 44 | + }); |
| 45 | +
|
| 46 | + for (const release of releases) { |
| 47 | + const isDevTag = /-dev\.\d+$/.test(release.tag_name || ""); |
| 48 | + if (isDevTag && release.draft) { |
| 49 | + await github.rest.repos.deleteRelease({ |
| 50 | + owner: context.repo.owner, |
| 51 | + repo: context.repo.repo, |
| 52 | + release_id: release.id, |
| 53 | + }); |
| 54 | + } |
| 55 | + } |
| 56 | +
|
| 57 | + - name: Remove previous dev tags |
| 58 | + env: |
| 59 | + GH_TOKEN: ${{ github.token }} |
| 60 | + run: | |
| 61 | + for tag in $(git tag --list 'v*-dev.*'); do |
| 62 | + git push origin ":refs/tags/${tag}" || true |
| 63 | + done |
| 64 | +
|
| 65 | + - name: Create dev draft prerelease |
| 66 | + uses: softprops/action-gh-release@v2 |
| 67 | + with: |
| 68 | + tag_name: ${{ steps.tag.outputs.dev_tag }} |
| 69 | + target_commitish: ${{ github.event.workflow_run.head_sha }} |
| 70 | + name: Dev Draft ${{ steps.tag.outputs.dev_tag }} |
| 71 | + generate_release_notes: true |
| 72 | + draft: true |
| 73 | + prerelease: true |
0 commit comments