|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*.*.*" |
| 7 | + |
| 8 | +jobs: |
| 9 | + create-release: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + outputs: |
| 14 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 15 | + tag_name: ${{ steps.get_version.outputs.tag_name }} |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout code |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Get version from tag |
| 22 | + id: get_version |
| 23 | + run: echo "tag_name=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 24 | + |
| 25 | + - name: Create Release |
| 26 | + id: create_release |
| 27 | + uses: softprops/action-gh-release@v2 |
| 28 | + with: |
| 29 | + tag_name: ${{ steps.get_version.outputs.tag_name }} |
| 30 | + name: ${{ steps.get_version.outputs.tag_name }} |
| 31 | + body: "Release ${{ steps.get_version.outputs.tag_name }} - Building collection and changelog..." |
| 32 | + draft: true |
| 33 | + prerelease: ${{ contains(steps.get_version.outputs.tag_name, '-') }} |
| 34 | + |
| 35 | + build-ansible-collection: |
| 36 | + needs: create-release |
| 37 | + runs-on: ubuntu-latest |
| 38 | + permissions: |
| 39 | + contents: write |
| 40 | + |
| 41 | + steps: |
| 42 | + - name: Checkout code |
| 43 | + uses: actions/checkout@v4 |
| 44 | + |
| 45 | + - name: Set up Python |
| 46 | + uses: actions/setup-python@v4 |
| 47 | + with: |
| 48 | + python-version: "3.x" |
| 49 | + |
| 50 | + - name: Install Ansible |
| 51 | + run: | |
| 52 | + python -m pip install --upgrade pip |
| 53 | + pip install ansible |
| 54 | +
|
| 55 | + - name: Build Ansible collection |
| 56 | + run: ansible-galaxy collection build |
| 57 | + |
| 58 | + - name: Get collection filename |
| 59 | + id: collection_file |
| 60 | + run: | |
| 61 | + COLLECTION_FILE=$(ls devil_imps-devil-*.tar.gz) |
| 62 | + echo "filename=$COLLECTION_FILE" >> $GITHUB_OUTPUT |
| 63 | +
|
| 64 | + - name: Read changelog content |
| 65 | + id: changelog |
| 66 | + run: | |
| 67 | + if [ -f "CHANGELOG.rst" ]; then |
| 68 | + echo "changelog_content<<EOF" >> $GITHUB_OUTPUT |
| 69 | + cat CHANGELOG.rst >> $GITHUB_OUTPUT |
| 70 | + echo "EOF" >> $GITHUB_OUTPUT |
| 71 | + else |
| 72 | + echo "changelog_content=No changelog available" >> $GITHUB_OUTPUT |
| 73 | + fi |
| 74 | +
|
| 75 | + - name: Upload collection and changelog to release |
| 76 | + uses: softprops/action-gh-release@v2 |
| 77 | + with: |
| 78 | + tag_name: ${{ needs.create-release.outputs.tag_name }} |
| 79 | + draft: false |
| 80 | + body: | |
| 81 | + ## Release ${{ needs.create-release.outputs.tag_name }} |
| 82 | +
|
| 83 | + ### Changelog |
| 84 | +
|
| 85 | + ``` |
| 86 | + ${{ steps.changelog.outputs.changelog_content }} |
| 87 | + ``` |
| 88 | +
|
| 89 | + ### Files |
| 90 | + - **Collection**: `${{ steps.collection_file.outputs.filename }}` |
| 91 | + - **Changelog**: `CHANGELOG.rst` |
| 92 | + files: | |
| 93 | + ${{ steps.collection_file.outputs.filename }} |
| 94 | + CHANGELOG.rst |
0 commit comments