|
| 1 | +name: Draft Release |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened, closed] |
| 6 | + paths: |
| 7 | + - VERSION |
| 8 | + branches: [main] |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + pull-requests: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + validate-release-commit: |
| 16 | + if: > |
| 17 | + !(github.event.pull_request.merged == true && |
| 18 | + !contains(join(github.event.pull_request.labels.*.name), 'release')) |
| 19 | +
|
| 20 | + runs-on: ubuntu-latest |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Checkout merge |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + |
| 28 | + - name: Get release commit info |
| 29 | + id: version |
| 30 | + run: | |
| 31 | + ver=$(cat VERSION) |
| 32 | + if ! echo "$ver" | grep -Eq '^[0-9]{4}\.[0-9]{2}\.[0-9]+$'; then |
| 33 | + echo "Invalid version format: $ver" |
| 34 | + exit 1 |
| 35 | + fi |
| 36 | +
|
| 37 | + echo "version=$ver" >> $GITHUB_OUTPUT |
| 38 | +
|
| 39 | + headline="$(git show --format=%s ${{github.event.pull_request.head.sha}})" |
| 40 | + if ! echo "$headline" | grep -Eq "^[Rr]elease microcom $ver$"; then |
| 41 | + echo "Invalid commit headline: $headline" |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | +
|
| 45 | + body="$( |
| 46 | + git show -s --format=%b ${{github.event.pull_request.head.sha}} \ |
| 47 | + | sed -E '/^Signed-off-by: /d' |
| 48 | + )" |
| 49 | +
|
| 50 | + echo 'body<<EOF' >> $GITHUB_OUTPUT |
| 51 | + echo "$body" >> $GITHUB_OUTPUT |
| 52 | + echo 'EOF' >> $GITHUB_OUTPUT |
| 53 | +
|
| 54 | + - name: Install Dependencies |
| 55 | + run: sudo apt install -y libreadline6-dev autoconf automake |
| 56 | + |
| 57 | + - name: Build release packages |
| 58 | + run: | |
| 59 | + autoreconf -i |
| 60 | + ./configure |
| 61 | + make check |
| 62 | + make dist |
| 63 | +
|
| 64 | + # DRAFT release on pr creation and update |
| 65 | + - name: Create or update release draft |
| 66 | + if: github.event.pull_request.merged == false |
| 67 | + uses: softprops/action-gh-release@v2 |
| 68 | + with: |
| 69 | + draft: true |
| 70 | + tag_name: v${{steps.version.outputs.version}} |
| 71 | + name: microcom ${{steps.version.outputs.version}} |
| 72 | + body: ${{steps.version.outputs.body}} |
| 73 | + files: | |
| 74 | + microcom-*.tar.gz |
| 75 | + microcom-*.tar.xz |
| 76 | +
|
| 77 | + # PUBLISH release on merge |
| 78 | + - name: Publish release on merge |
| 79 | + if: github.event.pull_request.merged == true |
| 80 | + uses: softprops/action-gh-release@v2 |
| 81 | + with: |
| 82 | + draft: false |
| 83 | + tag_name: v${{steps.version.outputs.version}} |
| 84 | + files: | |
| 85 | + microcom-*.tar.gz |
| 86 | + microcom-*.tar.xz |
| 87 | +
|
| 88 | + - run: gh pr edit "$NUMBER" --add-label "$LABELS" |
| 89 | + if: github.event.pull_request.merged == false |
| 90 | + env: |
| 91 | + GH_TOKEN: ${{secrets.GITHUB_TOKEN}} |
| 92 | + GH_REPO: ${{github.repository}} |
| 93 | + NUMBER: ${{github.event.pull_request.number}} |
| 94 | + LABELS: release |
| 95 | + |
| 96 | + - run: gh pr comment "$NUMBER" --body "Release published!" |
| 97 | + if: github.event.pull_request.merged == true |
| 98 | + env: |
| 99 | + GH_TOKEN: ${{secrets.GITHUB_TOKEN}} |
| 100 | + GH_REPO: ${{github.repository}} |
| 101 | + NUMBER: ${{github.event.pull_request.number}} |
| 102 | + LABELS: release |
0 commit comments