From c4d7f9e243059a7312a798168441ac8d9cdbdee0 Mon Sep 17 00:00:00 2001 From: Aaron Shaw Date: Mon, 6 Dec 2021 19:18:23 +0000 Subject: [PATCH] feat: pull gateway_mfr build from upstream to reduce build time - pull gateway_mfr build from upstream - update pypi and test-pypi actions - add action to check gateway-mfr-rs version weekly and auto-update if necessary - remove old unused backup action Closes: #43 --- .../workflows/publish-gateway-mfr-rs.yml.bak | 72 ------------------ .github/workflows/publish-to-pypi-test.yml | 73 ++++++------------- .github/workflows/publish-to-pypi.yml | 69 ++++++------------ .github/workflows/update-gateway-mfr-rs.yml | 67 +++++++++++++++++ 4 files changed, 113 insertions(+), 168 deletions(-) delete mode 100644 .github/workflows/publish-gateway-mfr-rs.yml.bak create mode 100644 .github/workflows/update-gateway-mfr-rs.yml diff --git a/.github/workflows/publish-gateway-mfr-rs.yml.bak b/.github/workflows/publish-gateway-mfr-rs.yml.bak deleted file mode 100644 index 4e780a3..0000000 --- a/.github/workflows/publish-gateway-mfr-rs.yml.bak +++ /dev/null @@ -1,72 +0,0 @@ -name: Periodically check for updates, build and release gateway-mfr-rs - -on: - schedule: - - cron: "0 0 * * 0" # Run weekly on sunday at 00:00 - workflow_dispatch: - -jobs: - rust-compile: - name: Build gateway-mfr-rs - runs-on: ubuntu-latest - steps: - - name: Check out repository - uses: actions/checkout@v2 - - name: Get Latest Release - id: latest_version - uses: abatilo/release-info-action@v1.3.0 - with: - owner: helium - repo: gateway-mfr-rs - - name: Perform check and update - env: - LATEST_GA: ${{ steps.latest_version.outputs.latest_tag }} - run: | - GITHUB_BRANCH=$( echo "${{ github.ref }}" | sed 's/refs\/heads\///g' ) - - echo "LATEST_GA=$LATEST_GA" >> $GITHUB_ENV - echo "GITHUB_BRANCH=$GITHUB_BRANCH" >> $GITHUB_ENV - - # Get the latest GA release - if grep -q "$LATEST_GA" Dockerfile; then - echo "We're on the latest Helium gateway-rs release $LATEST_GA." - exit 0 - else - echo "We're not on the latest Helium gateway-rs release. Updating to $LATEST_GA." - sed -i -E '2 s/GATEWAY_RS_RELEASE=.*/GATEWAY_RS_RELEASE='$LATEST_GA'/g' Dockerfile - UPDATED=true - echo "UPDATED=$UPDATED" >> $GITHUB_ENV - exit 0 - fi - - name: Install stable toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - target: aarch64-unknown-linux-musl - override: true - - - name: Clone repo - env: - LATEST_GA: ${{ steps.latest_version.outputs.latest_tag }} - run: | - git clone --branch $LATEST_GA https://github.com/helium/gateway-mfr-rs.git . - - name: Run cargo check - uses: actions-rs/cargo@v1 - with: - use-cross: true - command: check - - - name: Build gateway-mfr-rs - uses: actions-rs/cargo@v1 - with: - use-cross: true - command: build - args: --target aarch64-unknown-linux-musl --release - - - name: Copy release file - run: | - cp ./target/aarch64-unknown-linux-musl/release/gateway_mfr gateway_mfr - - uses: actions/upload-artifact@v2 - with: - name: gateway_mfr - path: ./gateway_mfr diff --git a/.github/workflows/publish-to-pypi-test.yml b/.github/workflows/publish-to-pypi-test.yml index 43cc1ae..544e3f2 100644 --- a/.github/workflows/publish-to-pypi-test.yml +++ b/.github/workflows/publish-to-pypi-test.yml @@ -3,47 +3,9 @@ name: Publish Python 🐍 distribution 📦 to TestPyPI on: [push] jobs: - rust-compile: - name: Build gateway-mfr-rs - runs-on: ubuntu-latest - steps: - - name: Install stable toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - target: arm-unknown-linux-gnueabihf - override: true - - - name: Clone repo - run: | - git clone --branch v0.1.5 https://github.com/helium/gateway-mfr-rs.git . - - - name: Run cargo check - uses: actions-rs/cargo@v1 - with: - use-cross: true - command: check - - - name: Build gateway-mfr-rs - uses: actions-rs/cargo@v1 - with: - use-cross: true - command: build - args: --target arm-unknown-linux-gnueabihf --release - - - name: Copy release file - run: | - cp ./target/arm-unknown-linux-gnueabihf/release/gateway_mfr gateway_mfr - - - uses: actions/upload-artifact@v2 - with: - name: gateway_mfr - path: ./gateway_mfr - build-n-publish: name: Build and publish Python 🐍 distribution 📦 to TestPyPI runs-on: ubuntu-18.04 - needs: [rust-compile] steps: - uses: actions/checkout@master @@ -53,18 +15,33 @@ jobs: with: python-version: 3.7 - - uses: actions/download-artifact@v2 - with: - name: gateway_mfr - path: ./gateway_mfr - - - name: Move gateway_mfr in place + - name: Fetch gateway-mfr-rs + env: + GATEWAY_MFR_RS_RELEASE: v0.1.6 run: | - chmod +x gateway_mfr/gateway_mfr + wget "https://github.com/helium/gateway-mfr-rs/releases/download/${GATEWAY_MFR_RS_RELEASE}/gateway-mfr-${GATEWAY_MFR_RS_RELEASE}-arm-unknown-linux-gnueabihf.tar.gz" + wget "https://github.com/helium/gateway-mfr-rs/releases/download/${GATEWAY_MFR_RS_RELEASE}/gateway-mfr-${GATEWAY_MFR_RS_RELEASE}-arm-unknown-linux-gnueabihf.checksum" + SHA256=$( shasum -a 256 "gateway-mfr-${GATEWAY_MFR_RS_RELEASE}-arm-unknown-linux-gnueabihf.tar.gz" ) + + # Verify the checksum + if grep -q "${SHA256}" "gateway-mfr-${GATEWAY_MFR_RS_RELEASE}-arm-unknown-linux-gnueabihf.checksum"; then + echo "Checksum verified for gateway_mfr." + exit 0 + else + echo "Checksum does not match. Please check download manually and rerun!" + exit 1 + fi + + # Unpack the tarball + tar -xvf "gateway-mfr-${GATEWAY_MFR_RS_RELEASE}-arm-unknown-linux-gnueabihf.tar.gz" + + - name: Change permissions on gateway_mfr + run: | + chmod +x gateway_mfr - name: Move gateway_mfr in place run: | - mv gateway_mfr/gateway_mfr hm_pyhelper/ + mv gateway_mfr hm_pyhelper/ - name: Install pypa/build run: | @@ -79,10 +56,6 @@ jobs: name: wheels path: ./dist/* - - name: Get changed files - id: changed-files - uses: tj-actions/changed-files@v2.1 - - name: Publish distribution 📦 to Test PyPI uses: pypa/gh-action-pypi-publish@master with: diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index a674e06..2d4b0d3 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -6,47 +6,9 @@ on: workflow_dispatch: jobs: - rust-compile: - name: Build gateway-mfr-rs - runs-on: ubuntu-latest - steps: - - name: Install stable toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - target: arm-unknown-linux-gnueabihf - override: true - - - name: Clone repo - run: | - git clone --branch v0.1.5 https://github.com/helium/gateway-mfr-rs.git . - - - name: Run cargo check - uses: actions-rs/cargo@v1 - with: - use-cross: true - command: check - - - name: Build gateway-mfr-rs - uses: actions-rs/cargo@v1 - with: - use-cross: true - command: build - args: --target arm-unknown-linux-gnueabihf --release - - - name: Copy release file - run: | - cp ./target/arm-unknown-linux-gnueabihf/release/gateway_mfr gateway_mfr - - - uses: actions/upload-artifact@v2 - with: - name: gateway_mfr - path: ./gateway_mfr - build-n-publish: name: Build and publish Python 🐍 distribution 📦 to PyPI runs-on: ubuntu-18.04 - needs: [rust-compile] steps: - uses: actions/checkout@master @@ -56,18 +18,33 @@ jobs: with: python-version: 3.7 - - uses: actions/download-artifact@v2 - with: - name: gateway_mfr - path: ./gateway_mfr + - name: Fetch gateway-mfr-rs + env: + GATEWAY_MFR_RS_RELEASE: v0.1.6 + run: | + wget "https://github.com/helium/gateway-mfr-rs/releases/download/${GATEWAY_MFR_RS_RELEASE}/gateway-mfr-${GATEWAY_MFR_RS_RELEASE}-arm-unknown-linux-gnueabihf.tar.gz" + wget "https://github.com/helium/gateway-mfr-rs/releases/download/${GATEWAY_MFR_RS_RELEASE}/gateway-mfr-${GATEWAY_MFR_RS_RELEASE}-arm-unknown-linux-gnueabihf.checksum" + SHA256=$( shasum -a 256 "gateway-mfr-${GATEWAY_MFR_RS_RELEASE}-arm-unknown-linux-gnueabihf.tar.gz" ) + + # Verify the checksum + if grep -q "${SHA256}" "gateway-mfr-${GATEWAY_MFR_RS_RELEASE}-arm-unknown-linux-gnueabihf.checksum"; then + echo "Checksum verified for gateway_mfr." + exit 0 + else + echo "Checksum does not match. Please check download manually and rerun!" + exit 1 + fi + + # Unpack the tarball + tar -xvf "gateway-mfr-${GATEWAY_MFR_RS_RELEASE}-arm-unknown-linux-gnueabihf.tar.gz" - - name: Move gateway_mfr in place + - name: Change permissions on gateway_mfr run: | - chmod +x gateway_mfr/gateway_mfr + chmod +x gateway_mfr - name: Move gateway_mfr in place run: | - mv gateway_mfr/gateway_mfr hm_pyhelper/ + mv gateway_mfr hm_pyhelper/ - name: Install pypa/build run: | @@ -81,7 +58,7 @@ jobs: with: name: wheels path: ./dist/* - + - name: Get Latest Release id: latest_version uses: abatilo/release-info-action@v1.3.0 diff --git a/.github/workflows/update-gateway-mfr-rs.yml b/.github/workflows/update-gateway-mfr-rs.yml new file mode 100644 index 0000000..778787a --- /dev/null +++ b/.github/workflows/update-gateway-mfr-rs.yml @@ -0,0 +1,67 @@ +name: Check if we're using the latest Gateway MFR (gateway-mfr-rs) release + +on: + schedule: + - cron: "0 0 * * 0" # Run weekly on sunday + workflow_dispatch: + +jobs: + latest-version: + name: Get Latest Release + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v2 + - name: Get Latest Release + id: latest_version + uses: abatilo/release-info-action@v1.3.0 + with: + owner: helium + repo: gateway-mfr-rs + - name: Perform check and update + env: + GATEWAY_MFR_RS_RELEASE: ${{ steps.latest_version.outputs.latest_tag }} + run: | + GITHUB_BRANCH=$( echo "${{ github.ref }}" | sed 's/refs\/heads\///g' ) + CHECK_LATEST_RELEASE="GATEWAY_MFR_RS_RELEASE: ${GATEWAY_MFR_RS_RELEASE}" + + echo "GATEWAY_MFR_RS_RELEASE=$GATEWAY_MFR_RS_RELEASE" >> $GITHUB_ENV + echo "GITHUB_BRANCH=$GITHUB_BRANCH" >> $GITHUB_ENV + + # Get the latest gateway-mfr-rs release + if grep -q "$CHECK_LATEST_RELEASE" .github/workflows/publish-to-pypi-test.yml; then + echo "We're on the latest Helium gateway-mfr-rs release $GATEWAY_MFR_RS_RELEASE." + exit 0 + else + echo "We're not on the latest Helium gateway-mfr-rs release. Updating to $GATEWAY_MFR_RS_RELEASE." + sed -i -E 's/GATEWAY_MFR_RS_RELEASE: v.*/GATEWAY_MFR_RS_RELEASE: '$GATEWAY_MFR_RS_RELEASE'/g' .github/workflows/publish-to-pypi-test.yml + sed -i -E 's/GATEWAY_MFR_RS_RELEASE: v.*/GATEWAY_MFR_RS_RELEASE: '$GATEWAY_MFR_RS_RELEASE'/g' .github/workflows/publish-to-pypi.yml + UPDATED=true + echo "UPDATED=$UPDATED" >> $GITHUB_ENV + exit 0 + fi + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 + with: + commit-message: Update gateway-mfr-rs to latest release ${{ env.GATEWAY_MFR_RS_RELEASE }} + branch: gateway-mfr-rs/${{ env.GATEWAY_MFR_RS_RELEASE }} + delete-branch: true + base: master + title: "gateway-mfr-rs: Update to latest release ${{ env.GATEWAY_MFR_RS_RELEASE }}" + body: | + Update gateway-mfr-rs to latest release ${{ env.GATEWAY_MFR_RS_RELEASE }} + Ref https://github.com/helium/gateway-mfr-rs/releases/tag/${{ env.GATEWAY_MFR_RS_RELEASE }} + draft: false + - name: Report Status + if: env.UPDATED == 'true' + uses: ravsamhq/notify-slack-action@master + with: + status: ${{ job.status }} + notification_title: 'Gateway-mfr-rs has been updated to ${{ env.GATEWAY_MFR_RS_RELEASE }}. Please review PR!' + message_format: '{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}>' + footer: '<{run_url}|View Run> | Linked Repo <{repo_url}|{repo}> | <{workflow_url}|View Workflow>' + mention_groups: 'S02GCFWL27R' + notify_when: 'success' + token: ${{ secrets.GITHUB_TOKEN }} + env: + SLACK_WEBHOOK_URL: ${{ secrets.MINER_MONITORING_SLACK }}