|
| 1 | +name: 'S2DM Compose' |
| 2 | +description: 'Compose GraphQL schema files and optionally create a release' |
| 3 | +author: 'COVESA' |
| 4 | + |
| 5 | +inputs: |
| 6 | + repository-path: |
| 7 | + description: 'Path to the git repository root' |
| 8 | + required: true |
| 9 | + |
| 10 | + spec-path: |
| 11 | + description: 'Path to the spec directory relative to the root of the repository' |
| 12 | + required: false |
| 13 | + default: 'spec' |
| 14 | + |
| 15 | + create-release: |
| 16 | + description: 'Whether to create a GitHub release with the composed schema' |
| 17 | + required: false |
| 18 | + default: 'false' |
| 19 | + |
| 20 | + github-token: |
| 21 | + description: 'GitHub token for creating releases (required if create-release is true)' |
| 22 | + required: false |
| 23 | + default: '' |
| 24 | + |
| 25 | + s2dm-path: |
| 26 | + description: 'Path where S2DM repository will be checked out' |
| 27 | + required: false |
| 28 | + default: 's2dm' |
| 29 | + |
| 30 | +outputs: |
| 31 | + composed-schema-path: |
| 32 | + description: 'Path to the composed schema file' |
| 33 | + value: ${{ steps.compose.outputs.SCHEMA_PATH }} |
| 34 | + |
| 35 | + version-bump: |
| 36 | + description: 'Type of version bump (major, minor, patch, none)' |
| 37 | + value: ${{ steps.version-check.outputs.VERSION_BUMP }} |
| 38 | + |
| 39 | + latest-tag: |
| 40 | + description: 'The latest git tag after release' |
| 41 | + value: ${{ steps.get-latest-tag.outputs.LATEST_TAG }} |
| 42 | + |
| 43 | +runs: |
| 44 | + using: "composite" |
| 45 | + steps: |
| 46 | + - name: Checkout S2DM repository |
| 47 | + uses: actions/checkout@v4 |
| 48 | + with: |
| 49 | + repository: COVESA/s2dm |
| 50 | + path: ${{ inputs.s2dm-path }} |
| 51 | + |
| 52 | + - name: Install Python |
| 53 | + uses: actions/setup-python@v5 |
| 54 | + with: |
| 55 | + python-version: '3.13' |
| 56 | + |
| 57 | + - name: Install uv |
| 58 | + uses: astral-sh/setup-uv@v4 |
| 59 | + with: |
| 60 | + version: "latest" |
| 61 | + |
| 62 | + - name: Install S2DM dependencies |
| 63 | + working-directory: ${{ inputs.s2dm-path }} |
| 64 | + shell: bash |
| 65 | + run: | |
| 66 | + uv sync --frozen |
| 67 | +
|
| 68 | + - name: Activate venv |
| 69 | + shell: bash |
| 70 | + run: | |
| 71 | + echo "${{ github.workspace }}/${{ inputs.s2dm-path }}/.venv/bin" >> $GITHUB_PATH |
| 72 | +
|
| 73 | + - name: Verify S2DM installation |
| 74 | + shell: bash |
| 75 | + run: | |
| 76 | + s2dm --help |
| 77 | +
|
| 78 | + - name: Prepare temp directory |
| 79 | + shell: bash |
| 80 | + run: | |
| 81 | + mkdir -p ${{ github.workspace }}/.s2dm-compose |
| 82 | +
|
| 83 | + - name: Compose GraphQL schema |
| 84 | + id: compose |
| 85 | + working-directory: ${{ inputs.repository-path }} |
| 86 | + shell: bash |
| 87 | + run: | |
| 88 | + s2dm compose -s ${{ inputs.spec-path }} -o ${{ github.workspace }}/.s2dm-compose/schema.graphql |
| 89 | + echo "SCHEMA_PATH=${{ github.workspace }}/.s2dm-compose/schema.graphql" >> "$GITHUB_OUTPUT" |
| 90 | +
|
| 91 | + - name: Validate release prerequisites |
| 92 | + if: inputs.create-release == 'true' |
| 93 | + working-directory: ${{ inputs.repository-path }} |
| 94 | + shell: bash |
| 95 | + run: | |
| 96 | + if [ ! -f ".bumpversion.toml" ]; then |
| 97 | + echo "ERROR: .bumpversion.toml not found but create-release is true" |
| 98 | + exit 1 |
| 99 | + fi |
| 100 | + if [ -z "${{ inputs.github-token }}" ]; then |
| 101 | + echo "ERROR: github-token is required when create-release is true" |
| 102 | + exit 1 |
| 103 | + fi |
| 104 | +
|
| 105 | + - name: Download latest release |
| 106 | + if: inputs.create-release == 'true' |
| 107 | + working-directory: ${{ inputs.repository-path }} |
| 108 | + env: |
| 109 | + GITHUB_TOKEN: ${{ inputs.github-token }} |
| 110 | + shell: bash |
| 111 | + run: | |
| 112 | + mkdir -p ${{ github.workspace }}/.previous-release |
| 113 | + gh release download --pattern "${{ inputs.output-path }}" --dir ${{ github.workspace }}/.previous-release || echo "No previous release found" |
| 114 | +
|
| 115 | + - name: Check version bump |
| 116 | + if: inputs.create-release == 'true' |
| 117 | + id: version-check |
| 118 | + shell: bash |
| 119 | + run: | |
| 120 | + VERSION_BUMP=major |
| 121 | + CONTINUE=false |
| 122 | + if [ -f "${{ github.workspace }}/.previous-release/${{ inputs.output-path }}" ]; then |
| 123 | + echo "Previous release found, checking for changes" |
| 124 | + VERSION_BUMP=$(s2dm check version-bump -s ${{ inputs.spec-path }} -p ${{ github.workspace }}/.previous-release/${{ inputs.output-path }} --output-type | tail -n 1) |
| 125 | + if [[ "$VERSION_BUMP" != "none" ]]; then |
| 126 | + echo "Changes detected: $VERSION_BUMP" |
| 127 | + CONTINUE=true |
| 128 | + else |
| 129 | + echo "No changes detected, skipping release" |
| 130 | + fi |
| 131 | + else |
| 132 | + echo "No previous release found, creating initial release" |
| 133 | + CONTINUE=true |
| 134 | + fi |
| 135 | + echo "VERSION_BUMP=$VERSION_BUMP" >> "$GITHUB_OUTPUT" |
| 136 | + echo "CONTINUE=$CONTINUE" >> "$GITHUB_OUTPUT" |
| 137 | +
|
| 138 | + - name: Bump version and push tags |
| 139 | + if: inputs.create-release == 'true' && steps.version-check.outputs.CONTINUE == 'true' |
| 140 | + working-directory: ${{ inputs.repository-path }} |
| 141 | + shell: bash |
| 142 | + run: | |
| 143 | + git config --local user.email "s2dm-automation-action@covesa.global" |
| 144 | + git config --local user.name "S2DM Automation Action" |
| 145 | + bump-my-version bump ${{ steps.version-check.outputs.VERSION_BUMP }} --config-file ./.bumpversion.toml |
| 146 | + git push origin ${{ github.ref_name }} |
| 147 | + git push origin --tags |
| 148 | +
|
| 149 | + - name: Get latest tag |
| 150 | + if: inputs.create-release == 'true' && steps.version-check.outputs.CONTINUE == 'true' |
| 151 | + id: get-latest-tag |
| 152 | + working-directory: ${{ inputs.repository-path }} |
| 153 | + shell: bash |
| 154 | + run: | |
| 155 | + LATEST_TAG=$(git describe --tags --abbrev=0) |
| 156 | + echo "LATEST_TAG=$LATEST_TAG" >> "$GITHUB_OUTPUT" |
| 157 | +
|
| 158 | + - name: Create release |
| 159 | + if: inputs.create-release == 'true' && steps.version-check.outputs.CONTINUE == 'true' |
| 160 | + working-directory: ${{ inputs.repository-path }} |
| 161 | + env: |
| 162 | + GITHUB_TOKEN: ${{ inputs.github-token }} |
| 163 | + shell: bash |
| 164 | + run: | |
| 165 | + LATEST_TAG="${{ steps.get-latest-tag.outputs.LATEST_TAG }}" |
| 166 | + gh release create "${LATEST_TAG}" \ |
| 167 | + --title "Release ${LATEST_TAG}" \ |
| 168 | + --notes "This release contains the composed GraphQL schema." \ |
| 169 | + ${{ github.workspace }}/.s2dm-compose/schema.graphql |
0 commit comments