|
| 1 | +name: Prerelease on Tag |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + |
| 8 | +jobs: |
| 9 | + pre-release: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Checkout repository |
| 13 | + uses: actions/checkout@v4 |
| 14 | + with: |
| 15 | + fetch-depth: 0 # Fetch all history for all tags and branches |
| 16 | + |
| 17 | + - name: Detect single custom component directory |
| 18 | + id: detect_integration |
| 19 | + run: | |
| 20 | + DIR_COUNT=$(find custom_components -maxdepth 1 -type d | wc -l) |
| 21 | + if [ "$DIR_COUNT" -ne "1" ]; then |
| 22 | + echo "Error: There must be exactly one custom component directory." >&2 |
| 23 | + exit 1 |
| 24 | + fi |
| 25 | + DOMAIN=$(basename $(find custom_components -maxdepth 1 -type d)) |
| 26 | + echo "::set-output name=domain::$DOMAIN" |
| 27 | +
|
| 28 | + - name: Install JQ |
| 29 | + run: sudo apt-get install jq |
| 30 | + |
| 31 | + - name: Extract version from current commit |
| 32 | + id: current_version |
| 33 | + run: | |
| 34 | + DOMAIN=${{ steps.detect_integration.outputs.domain }} |
| 35 | + VERSION=$(jq -r '.version' custom_components/$DOMAIN/manifest.json) |
| 36 | + echo "::set-output name=version::$VERSION" |
| 37 | +
|
| 38 | + - name: Extract version from previous commit |
| 39 | + id: previous_version |
| 40 | + run: | |
| 41 | + DOMAIN=${{ steps.detect_integration.outputs.domain }} |
| 42 | + PREV_VERSION=$(git show HEAD~:custom_components/$DOMAIN/manifest.json | jq -r '.version') |
| 43 | + echo "::set-output name=version::$PREV_VERSION" |
| 44 | +
|
| 45 | + - name: Check if version changed |
| 46 | + if: steps.current_version.outputs.version != steps.previous_version.outputs.version |
| 47 | + run: echo "Version changed." |
| 48 | + |
| 49 | + - name: Create Tag |
| 50 | + if: steps.current_version.outputs.version != steps.previous_version.outputs.version |
| 51 | + uses: actions/github-script@v7 |
| 52 | + with: |
| 53 | + script: | |
| 54 | + const version = '${{ steps.current_version.outputs.version }}'; |
| 55 | + github.rest.git.createRef({ |
| 56 | + owner: context.repo.owner, |
| 57 | + repo: context.repo.repo, |
| 58 | + ref: `refs/tags/v${version}`, |
| 59 | + sha: '${{ github.sha }}' |
| 60 | + }); |
| 61 | +
|
| 62 | + - name: Create Pre-release |
| 63 | + if: steps.current_version.outputs.version != steps.previous_version.outputs.version |
| 64 | + uses: actions/github-script@v7 |
| 65 | + with: |
| 66 | + script: | |
| 67 | + const version = '${{ steps.current_version.outputs.version }}'; |
| 68 | + github.rest.repos.createRelease({ |
| 69 | + owner: context.repo.owner, |
| 70 | + repo: context.repo.repo, |
| 71 | + tag_name: `v${version}`, |
| 72 | + name: `v${version}`, |
| 73 | + body: "## :new: Нововведения\n\n<!-- ... -->\n\n## :bug: Исправления\n\n<!-- ... -->\n\n## :wrench: Изменения\n\n<!-- ... -->\n\n## :information_source: Примечания\n\n<!-- ... -->", |
| 74 | + draft: false, |
| 75 | + prerelease: true, |
| 76 | + }); |
0 commit comments