|
| 1 | +name: Publish Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + prerelease: |
| 7 | + type: boolean |
| 8 | + description: "Prerelease" |
| 9 | + # Whether to create a prerelease or proper release |
| 10 | + default: true |
| 11 | + required: true |
| 12 | + swift_format_version: |
| 13 | + type: string |
| 14 | + default: 601.0.0 |
| 15 | + description: "swift-format version" |
| 16 | + # The version of swift-format to tag. If this is a prerelease, `-prerelease-<date>` is added to this version. |
| 17 | + required: true |
| 18 | + swift_syntax_tag: |
| 19 | + type: string |
| 20 | + default: 601.0.0 |
| 21 | + description: "swift-syntax version" |
| 22 | + # The swift-syntax version to depend on. If this is a prerelease, the latest swift-syntax prerelease tag for this version is used. |
| 23 | + required: true |
| 24 | + |
| 25 | +jobs: |
| 26 | + check_triggering_actor: |
| 27 | + name: Check user is allowed to create release |
| 28 | + # Only a single user should be allowed to create releases to avoid two people triggering the creation of a release |
| 29 | + # at the same time. If the release manager changes between users, update this condition. |
| 30 | + runs-on: ubuntu-latest |
| 31 | + steps: |
| 32 | + - run: | |
| 33 | + if [[ "${{ github.triggering_actor }}" != "ahoppen" ]]; then |
| 34 | + echo "${{ github.triggering_actor }} is not allowed to create a release" |
| 35 | + exit 1 |
| 36 | + fi |
| 37 | + define_tags: |
| 38 | + name: Determine dependent swift-syntax version and prerelease date |
| 39 | + runs-on: ubuntu-latest |
| 40 | + outputs: |
| 41 | + swift_syntax_tag: ${{ steps.swift_syntax_tag.outputs.swift_syntax_tag }} |
| 42 | + swift_format_version: ${{ steps.swift_format_version.outputs.swift_format_version }} |
| 43 | + steps: |
| 44 | + - name: Determine swift-syntax tag to depend on |
| 45 | + id: swift_syntax_tag |
| 46 | + shell: bash |
| 47 | + run: | |
| 48 | + if [[ "${{ github.event.inputs.prerelease }}" == "false" ]]; then |
| 49 | + SWIFT_SYNTAX_TAG="${{ github.event.inputs.swift_syntax_tag }}" |
| 50 | + else |
| 51 | + git clone https://github.com/swiftlang/swift-syntax.git |
| 52 | + cd swift-syntax |
| 53 | + SWIFT_SYNTAX_TAG="$(git tag | grep ${{ github.event.inputs.swift_syntax_tag }}-prerelease | sort -r | head -1)" |
| 54 | + fi |
| 55 | +
|
| 56 | + echo "Using swift-syntax tag: $SWIFT_SYNTAX_TAG" |
| 57 | + echo "swift_syntax_tag=$SWIFT_SYNTAX_TAG" >> "$GITHUB_OUTPUT" |
| 58 | + - name: Determine swift-format prerelease version |
| 59 | + id: swift_format_version |
| 60 | + run: | |
| 61 | + if [[ "${{ github.event.inputs.prerelease }}" == "false" ]]; then |
| 62 | + SWIFT_FORMAT_VERSION="${{ github.event.inputs.swift_format_version }}" |
| 63 | + else |
| 64 | + SWIFT_FORMAT_VERSION="${{ github.event.inputs.swift_format_version }}-prerelease-$(date +'%Y-%m-%d')" |
| 65 | + fi |
| 66 | + echo "Using swift-format version: $SWIFT_FORMAT_VERSION" |
| 67 | + echo "swift_format_version=$SWIFT_FORMAT_VERSION" >> "$GITHUB_OUTPUT" |
| 68 | + test_debug: |
| 69 | + name: Test in Debug configuration |
| 70 | + uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main |
| 71 | + needs: define_tags |
| 72 | + with: |
| 73 | + pre_build_command: bash .github/workflows/create-release-commits.sh '${{ needs.define_tags.outputs.swift_syntax_tag }}' '${{ needs.define_tags.outputs.swift_format_version }}' |
| 74 | + test_release: |
| 75 | + name: Test in Release configuration |
| 76 | + uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main |
| 77 | + needs: define_tags |
| 78 | + with: |
| 79 | + pre_build_command: bash .github/workflows/create-release-commits.sh '${{ needs.define_tags.outputs.swift_syntax_tag }}' '${{ needs.define_tags.outputs.swift_format_version }}' |
| 80 | + build_command: swift test -c release |
| 81 | + create_tag: |
| 82 | + name: Create Tag |
| 83 | + runs-on: ubuntu-latest |
| 84 | + needs: [check_triggering_actor, test_debug, test_release, define_tags] |
| 85 | + steps: |
| 86 | + - name: Checkout repository |
| 87 | + uses: actions/checkout@v4 |
| 88 | + - name: Create release commits |
| 89 | + run: bash .github/workflows/create-release-commits.sh '${{ needs.define_tags.outputs.swift_syntax_tag }}' '${{ needs.define_tags.outputs.swift_format_version }}' |
| 90 | + - name: Tag release |
| 91 | + run: | |
| 92 | + git tag "${{ needs.define_tags.outputs.swift_format_version }}" |
| 93 | + git push origin "${{ needs.define_tags.outputs.swift_format_version }}" |
| 94 | + - name: Create release |
| 95 | + env: |
| 96 | + GH_TOKEN: ${{ github.token }} |
| 97 | + run: | |
| 98 | + if [[ "${{ github.event.inputs.prerelease }}" != "true" ]]; then |
| 99 | + # Only create a release automatically for prereleases. For real releases, release notes should be crafted by hand. |
| 100 | + exit |
| 101 | + fi |
| 102 | + gh release create "${{ needs.define_tags.outputs.swift_format_version }}" \ |
| 103 | + --title "${{ needs.define_tags.outputs.swift_format_version }}" \ |
| 104 | + --prerelease |
| 105 | +
|
0 commit comments