|
| 1 | +name: Auto Release |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 4 * * *' # 12:00 UTC+8 |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + check-and-release: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + outputs: |
| 12 | + should_release: ${{ steps.check_diff.outputs.should_release }} |
| 13 | + new_tag: ${{ steps.generate_tag.outputs.new_tag }} |
| 14 | + latest_tag: ${{ steps.get_latest_tag.outputs.latest_tag }} |
| 15 | + steps: |
| 16 | + - name: Checkout repository |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | + - name: Get latest release tag |
| 22 | + id: get_latest_tag |
| 23 | + run: | |
| 24 | + latest_tag=$(git tag --sort=-version:refname | head -n 1) |
| 25 | + if [ -z "$latest_tag" ]; then |
| 26 | + echo "No previous release found" |
| 27 | + echo "latest_tag=" >> $GITHUB_OUTPUT |
| 28 | + else |
| 29 | + echo "Latest tag: $latest_tag" |
| 30 | + echo "latest_tag=$latest_tag" >> $GITHUB_OUTPUT |
| 31 | + fi |
| 32 | +
|
| 33 | + - name: Check for changes since last release |
| 34 | + id: check_diff |
| 35 | + run: | |
| 36 | + latest_tag="${{ steps.get_latest_tag.outputs.latest_tag }}" |
| 37 | + if [ -z "$latest_tag" ]; then |
| 38 | + echo "No previous release, will create first release" |
| 39 | + echo "should_release=true" >> $GITHUB_OUTPUT |
| 40 | + else |
| 41 | + diff_count=$(git rev-list ${latest_tag}..HEAD --count) |
| 42 | + if [ "$diff_count" -eq "0" ]; then |
| 43 | + echo "No changes since last release ($latest_tag)" |
| 44 | + echo "should_release=false" >> $GITHUB_OUTPUT |
| 45 | + else |
| 46 | + echo "Found $diff_count commits since last release" |
| 47 | + echo "should_release=true" >> $GITHUB_OUTPUT |
| 48 | + fi |
| 49 | + fi |
| 50 | +
|
| 51 | + - name: Generate CalVer tag |
| 52 | + id: generate_tag |
| 53 | + if: steps.check_diff.outputs.should_release == 'true' |
| 54 | + run: | |
| 55 | + # Get current date (UTC+8) |
| 56 | + TZ='Asia/Shanghai' year=$(date +%Y) |
| 57 | + TZ='Asia/Shanghai' month=$(date +%m) |
| 58 | + |
| 59 | + # Find all version in this year/month with 'v' prefix and 'r' suffix |
| 60 | + prefix="v${year}.${month}.r" |
| 61 | + existing_tags=$(git tag -l "${prefix}*" | sort -V) |
| 62 | + |
| 63 | + if [ -z "$existing_tags" ]; then |
| 64 | + # No version in this year/month, start from 1 |
| 65 | + micro=1 |
| 66 | + else |
| 67 | + # Micro + 1 |
| 68 | + last_tag=$(echo "$existing_tags" | tail -n 1) |
| 69 | + last_micro=$(echo "$last_tag" | sed "s/${prefix}//") |
| 70 | + micro=$((last_micro + 1)) |
| 71 | + fi |
| 72 | + |
| 73 | + new_tag="v${year}.${month}.r${micro}" |
| 74 | + echo "New tag: $new_tag" |
| 75 | + echo "new_tag=$new_tag" >> $GITHUB_OUTPUT |
| 76 | +
|
| 77 | + build: |
| 78 | + name: build artifacts |
| 79 | + needs: check-and-release |
| 80 | + if: needs.check-and-release.outputs.should_release == 'true' |
| 81 | + uses: ./.github/workflows/build.yml |
| 82 | + |
| 83 | + create-release: |
| 84 | + needs: [check-and-release, build] |
| 85 | + if: needs.check-and-release.outputs.should_release == 'true' |
| 86 | + runs-on: ubuntu-latest |
| 87 | + permissions: |
| 88 | + contents: write |
| 89 | + steps: |
| 90 | + - name: Checkout repository |
| 91 | + uses: actions/checkout@v4 |
| 92 | + with: |
| 93 | + fetch-depth: 0 |
| 94 | + |
| 95 | + - name: Download all artifacts |
| 96 | + uses: actions/download-artifact@v4 |
| 97 | + with: |
| 98 | + pattern: difftest-so-* |
| 99 | + path: release-artifacts |
| 100 | + |
| 101 | + - name: Prepare release assets |
| 102 | + run: | |
| 103 | + mkdir -p release-files |
| 104 | + cd release-artifacts |
| 105 | + ls -l |
| 106 | + new_tag="${{ needs.check-and-release.outputs.new_tag }}" |
| 107 | + for dir in difftest-so-*; do |
| 108 | + if [ -d "$dir" ]; then |
| 109 | + container_version=$(echo "$dir" | sed 's/difftest-so-//') |
| 110 | + cd "$dir" |
| 111 | + tar -czf "../../release-files/difftest-so-${new_tag}-${container_version}.tar.gz" . |
| 112 | + cd .. |
| 113 | + fi |
| 114 | + done |
| 115 | +
|
| 116 | + - name: Generate release notes |
| 117 | + run: | |
| 118 | + new_tag="${{ needs.check-and-release.outputs.new_tag }}" |
| 119 | + # Remove 'v' prefix for parsing |
| 120 | + version_num="${new_tag#v}" |
| 121 | + year=$(echo "$version_num" | cut -d'.' -f1) |
| 122 | + month=$(echo "$version_num" | cut -d'.' -f2) |
| 123 | + micro=$(echo "$version_num" | sed 's/.*r//') |
| 124 | + month_name=$(date -d "${year}-${month}-01" +"%B") |
| 125 | + release_date=$(TZ='Asia/Shanghai' date +"%B %-d, %Y") |
| 126 | + |
| 127 | + cat > RELEASE_NOTES.md << EOF |
| 128 | + Release ${new_tag} is the ${micro}th release in ${month_name} ${year}, released on ${release_date}. |
| 129 | + |
| 130 | + ## Artifacts |
| 131 | + The release includes pre-compiled difftest shared objects for different Ubuntu versions: |
| 132 | + - \`difftest-so-${new_tag}-ubuntu-20.04.tar.gz\`: Compiled on Ubuntu 20.04, good for CentOS 7. |
| 133 | + - \`difftest-so-${new_tag}-ubuntu-22.04.tar.gz\`: Compiled on Ubuntu 22.04 |
| 134 | + - \`difftest-so-${new_tag}-ubuntu-24.04.tar.gz\`: Compiled on Ubuntu 24.04 |
| 135 | + EOF |
| 136 | +
|
| 137 | + - name: Create Release |
| 138 | + uses: softprops/action-gh-release@v2 |
| 139 | + with: |
| 140 | + tag_name: ${{ needs.check-and-release.outputs.new_tag }} |
| 141 | + name: Release ${{ needs.check-and-release.outputs.new_tag }} |
| 142 | + body_path: RELEASE_NOTES.md |
| 143 | + draft: false |
| 144 | + prerelease: false |
| 145 | + generate_release_notes: true |
| 146 | + files: | |
| 147 | + release-files/*.tar.gz |
| 148 | + env: |
| 149 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments