1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
name: Release

on:
  workflow_dispatch:
  workflow_run:
    workflows: [CI]
    types: [completed]
    branches: [main]

permissions: {}

env:
  # workflow_run checks out the default branch head by default, which may have
  # moved past the commit CI actually validated.
  RELEASE_SHA: ${{ github.event.workflow_run.head_sha || github.sha }}

jobs:
  build:
    if: >-
      github.event_name == 'workflow_dispatch'
      || github.event.workflow_run.conclusion == 'success'
    runs-on: macos-latest
    permissions:
      contents: write # create GitHub release
    outputs:
      version: ${{ steps.version.outputs.version }}
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          ref: ${{ env.RELEASE_SHA }}
          persist-credentials: false

      - name: Calculate version
        id: version
        run: |
          CALVER=$(date -u +"%Y-%m-%d")
          echo "version=${CALVER}+${RELEASE_SHA::7}" >> "$GITHUB_OUTPUT"

      - name: Build
        run: |
          FRORK_VERSION="${STEPS_VERSION_OUTPUTS_VERSION}" cargo build --release -p frork-cli
          tar -czf frork-aarch64-apple-darwin.tar.gz -C target/release frork
        env:
          STEPS_VERSION_OUTPUTS_VERSION: ${{ steps.version.outputs.version }}

      - name: Publish
        run: |
          VERSION="${STEPS_VERSION_OUTPUTS_VERSION}"
          gh release create "v${VERSION}" \
            --title "v${VERSION}" \
            --generate-notes \
            --target "${RELEASE_SHA}" \
            frork-aarch64-apple-darwin.tar.gz
        env:
          GH_TOKEN: ${{ github.token }}
          STEPS_VERSION_OUTPUTS_VERSION: ${{ steps.version.outputs.version }}

  dotslash:
    needs: build
    runs-on: ubuntu-latest
    permissions:
      contents: write # upload release assets
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          ref: ${{ env.RELEASE_SHA }}
          persist-credentials: false

      - name: Generate DotSlash file
        uses: facebook/dotslash-publish-release@9c9ec027515c34db9282a09a25a9cab5880b2c52 # v2
        with:
          config: .github/dotslash-config.json
          tag: v${{ needs.build.outputs.version }}
        env:
          GITHUB_TOKEN: ${{ github.token }}