From bc7554b6d35de0cecdc510ff6dff0a5e9dc4c528 Mon Sep 17 00:00:00 2001 From: Stephen Leitnick Date: Sun, 30 Jun 2024 22:11:44 -0400 Subject: [PATCH 1/3] Improve release workflow --- .github/workflows/release.yaml | 61 +++++++++++++++++++--------------- check_version.py | 35 +++++++++++++++++++ 2 files changed, 69 insertions(+), 27 deletions(-) create mode 100644 check_version.py diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index b3535c5..be04f72 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -6,25 +6,20 @@ on: - 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: Check Release Version + 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() From 448d60d20104bfe41476bce3325a6daf761e550b Mon Sep 17 00:00:00 2001 From: Stephen Leitnick Date: Sun, 30 Jun 2024 22:13:57 -0400 Subject: [PATCH 2/3] Improve tag match --- .github/workflows/release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index be04f72..8a0ba08 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -3,7 +3,7 @@ name: Release on: push: tags: - - v* + - "v*.*.*" jobs: check-release-version: From 3ac8bf7808e83a883a56e24f14ef4c3d425d1116 Mon Sep 17 00:00:00 2001 From: Stephen Leitnick Date: Sun, 30 Jun 2024 22:15:06 -0400 Subject: [PATCH 3/3] Release job name --- .github/workflows/release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 8a0ba08..012c6ea 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -91,7 +91,7 @@ jobs: create-release: needs: ["build"] - name: Check Release Version + name: Create Release runs-on: ubuntu-latest steps: - name: Create artifact directory