diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index b3535c5..012c6ea 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -3,28 +3,23 @@ name: Release on: push: tags: - - v* + - "v*.*.*" jobs: - create-release: - name: Create Release + check-release-version: + name: Check Release Version runs-on: ubuntu-latest - outputs: - upload_url: ${{ steps.create_release.outputs.upload_url }} steps: - - name: Create Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Setup Python + uses: actions/setup-python@v5 with: - tag_name: ${{ github.ref }} - release_name: ${{ github.ref }} - draft: true - prerelease: false + python-version: "3.x" + + - name: Check tag version against cargo version + run: python check_version.py ${{ github.ref_name }} build: - needs: ["create-release"] + needs: ["check-release-version"] strategy: fail-fast: false matrix: @@ -60,7 +55,6 @@ jobs: shell: bash run: | echo "PROJECT_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV - echo "Version is ${{ env.PROJECT_VERSION }}" - name: Rust run: rustup toolchain install stable-${{ matrix.target }} --profile minimal --no-self-update @@ -89,24 +83,37 @@ jobs: zip ../release.zip * fi - - name: Upload Archive to Release - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ needs.create-release.outputs.upload_url }} - asset_path: release.zip - asset_name: ${{ env.BIN }}-${{ env.PROJECT_VERSION }}-${{ matrix.label }}.zip - asset_content_type: application/octet-stream - - name: Upload Archive to Artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: ${{ env.BIN }}-${{ env.PROJECT_VERSION }}-${{ matrix.label }}.zip path: release.zip - publish: + create-release: needs: ["build"] + name: Create Release + runs-on: ubuntu-latest + steps: + - name: Create artifact directory + shell: bash + run: mkdir gh_artifacts + + - name: Download artifacts + id: download-artifact + uses: dawidd6/action-download-artifact@v6 + with: + path: gh_artifacts + + - name: Create release + id: create_release + uses: softprops/action-gh-release@v2 + with: + draft: true + generate_release_notes: true + files: gh_artifacts/*.zip + + publish: + needs: ["create-release"] name: Publish runs-on: ubuntu-latest steps: diff --git a/check_version.py b/check_version.py new file mode 100644 index 0000000..ff240cf --- /dev/null +++ b/check_version.py @@ -0,0 +1,35 @@ +import sys + +def main(): + if len(sys.argv) <= 1: + print("missing version argument", file=sys.stderr) + exit(1) + + version = sys.argv[1] + cargo_version = "" + found_cargo_version = False + matched_version = False + + # Find first occurrence of "version = x.y.z" and assume that as the project version: + with open("Cargo.toml", mode="r") as cargo_file: + lines = cargo_file.readlines() + for line in lines: + pair = line[:-1].split(sep="=") + if len(pair) == 2 and pair[0].strip() == "version": + cargo_version = "v" + pair[1].strip()[1:-1] + matched_version = cargo_version == version + found_cargo_version = True + break + + if not found_cargo_version: + print("failed to find cargo version", file=sys.stderr) + exit(1) + + if not matched_version: + print(f"version mismatch (input: {version} | cargo: {cargo_version})", file=sys.stderr) + exit(1) + + print("versions matched") + +if __name__ == "__main__": + main()