chore(grass_docker-publish.yml): different tags for grass and grass-node #150
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker Build and Push | |
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
on: | |
schedule: | |
- cron: '0 0 * * *' # Runs at 00:00 UTC daily | |
push: | |
branches: [ "main" ] | |
workflow_dispatch: | |
permissions: # The permissions that the workflow has. The permissions are inherited from the job and can be customized. | |
contents: write | |
env: | |
GRASS_IMAGE_NAME: 'mrcolorrain/grass' | |
GRASS_NODE_IMAGE_NAME: 'mrcolorrain/grass-node' | |
TAG: 'latest' | |
MAX_DELAY: 30 | |
GRASS_VERSION_FILE_PATH: '.githubworkflows.grass_current_version' | |
GRASS_NODE_VERSION_FILE_PATH: '.githubworkflows.grass-node_current_version' | |
GRASS_RELEASE_URL: 'https://chromewebstore.google.com/detail/${{ secrets.EXTENSION_ID }}' | |
GRASS_NODE_RELEASE_URL: 'https://api.getgrass.io/extensionLatestRelease' | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Randomized Delay | |
run: sleep $((RANDOM % ${{ env.MAX_DELAY }})) | |
- name: Install jq tool # Useful for parsing JSON | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y jq | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Check for new Grass version | |
id: grass-version-check | |
run: | | |
ARCH=$(uname -m) | |
if [ "$ARCH" = "x86_64" ]; then | |
ARCH="amd64" | |
elif [ "$ARCH" = "aarch64" ]; then | |
ARCH="arm64" | |
else | |
echo "Unsupported architecture: $ARCH" && exit 1 | |
fi | |
echo "Detected runner architecture: $ARCH" | |
wget -q "${{ env.GRASS_RELEASE_URL }}" -O grass_extension_page.html | |
# Extract all version numbers matching the pattern | |
grep -Po '(?<=\\\"version\\\": \\\")([0-9]+\.[0-9]+\.[0-9]+)(?=\\\",)' grass_extension_page.html > grass_versions.txt | |
# Sort the versions using version sort and select the highest one | |
LATEST_GRASS_VERSION=$(sort -V grass_versions.txt | tail -n1) | |
echo "Latest Grass Version detected: $LATEST_GRASS_VERSION" | |
# Check the current version stored in the repository | |
if [ -f "${{ env.GRASS_VERSION_FILE_PATH }}" ]; then | |
echo "Current Grass version file ${{ env.GRASS_VERSION_FILE_PATH }} found" | |
CURRENT_GRASS_VERSION=$(cat "${{ env.GRASS_VERSION_FILE_PATH }}") | |
else | |
echo "Cannot find current Grass version file ${{ env.GRASS_VERSION_FILE_PATH }}. Creating a new one" | |
mkdir -p "$(dirname "${{ env.GRASS_VERSION_FILE_PATH }}")" | |
echo 'none' > "${{ env.GRASS_VERSION_FILE_PATH }}" | |
CURRENT_GRASS_VERSION='none' | |
fi | |
echo "Current Grass Version: $CURRENT_GRASS_VERSION" | |
if [ "$CURRENT_GRASS_VERSION" != "$LATEST_GRASS_VERSION" ] || [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
echo "New Grass version detected: $LATEST_GRASS_VERSION - Triggering build..." | |
echo "latest_grass_version=$LATEST_GRASS_VERSION" >> $GITHUB_ENV | |
echo "$LATEST_GRASS_VERSION" > "${{ env.GRASS_VERSION_FILE_PATH }}" | |
echo "grass_build=true" >> $GITHUB_OUTPUT | |
else | |
echo "No new Grass version detected. Skipping build" | |
echo "grass_build=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Check for new Grass-Node version | |
id: grass-node-version-check | |
run: | | |
# Attempt to fetch the latest Grass-Node version | |
wget -q "${{ env.GRASS_NODE_RELEASE_URL }}" -O grass_node_version.json || echo "none" > grass_node_version.json | |
# Attempt to parse the JSON file to extract the "version" field | |
LATEST_GRASS_NODE_VERSION=$(jq -r '.result.data.version' grass_node_version.json 2>/dev/null || echo "none") | |
# Check if parsing was successful | |
if [ "$LATEST_GRASS_NODE_VERSION" == "none" ]; then | |
echo "Failed to parse Grass-Node version from JSON. Using Grass version as fallback." | |
LATEST_GRASS_NODE_VERSION="${{ env.latest_grass_version }}" | |
fi | |
echo "Latest Grass-Node Version detected: $LATEST_GRASS_NODE_VERSION" | |
if [ -f "${{ env.GRASS_NODE_VERSION_FILE_PATH }}" ]; then | |
echo "Current Grass-Node version file ${{ env.GRASS_NODE_VERSION_FILE_PATH }} found" | |
CURRENT_GRASS_NODE_VERSION=$(cat "${{ env.GRASS_NODE_VERSION_FILE_PATH }}") | |
else | |
echo "Cannot find current Grass-Node version file ${{ env.GRASS_NODE_VERSION_FILE_PATH }}. Creating a new one" | |
mkdir -p "$(dirname "${{ env.GRASS_NODE_VERSION_FILE_PATH }}")" | |
echo 'none' > "${{ env.GRASS_NODE_VERSION_FILE_PATH }}" | |
CURRENT_GRASS_NODE_VERSION='none' | |
fi | |
echo "Current Grass-Node Version: $CURRENT_GRASS_NODE_VERSION" | |
if [ "$CURRENT_GRASS_NODE_VERSION" != "$LATEST_GRASS_NODE_VERSION" ]; then | |
echo "$LATEST_GRASS_NODE_VERSION" > "${{ env.GRASS_NODE_VERSION_FILE_PATH }}" | |
echo "latest_grass_node_version=$LATEST_GRASS_NODE_VERSION" >> $GITHUB_ENV | |
echo "grass_node_build=true" >> $GITHUB_OUTPUT | |
else | |
echo "No new Grass-Node version detected. Skipping build" | |
echo "grass_node_build=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Setup QEMU | |
if: steps.grass-version-check.outputs.grass_build == 'true' || steps.grass-node-version-check.outputs.grass_node_build == 'true' | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
if: steps.grass-version-check.outputs.grass_build == 'true' || steps.grass-node-version-check.outputs.grass_node_build == 'true' | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to DockerHub | |
if: steps.grass-version-check.outputs.grass_build == 'true' || steps.grass-node-version-check.outputs.grass_node_build == 'true' | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and Push Grass Image | |
if: steps.grass-version-check.outputs.grass_build == 'true' | |
uses: docker/build-push-action@v6 | |
with: | |
file: "grass.dockerfile" | |
push: true | |
tags: ${{ env.GRASS_IMAGE_NAME }}:${{ env.TAG }} | |
platforms: linux/amd64,linux/arm64,linux/arm/v7 | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Build and Push Grass-Node Image | |
if: steps.grass-node-version-check.outputs.grass_node_build == 'true' | |
uses: docker/build-push-action@v6 | |
with: | |
file: "grass-node.dockerfile" | |
push: true | |
tags: ${{ env.GRASS_NODE_IMAGE_NAME }}:${{ env.TAG }} | |
platforms: linux/amd64,linux/arm64,linux/arm/v7 | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Commit and push updated version files | |
if: steps.grass-version-check.outputs.grass_build == 'true' || steps.grass-node-version-check.outputs.grass_node_build == 'true' | |
run: | | |
git config --global user.name 'GitHub Actions' | |
git config --global user.email '[email protected]' | |
if [ "${{ steps.grass-version-check.outputs.grass_build }}" == "true" ]; then | |
git add "${{ env.GRASS_VERSION_FILE_PATH }}" | |
git commit -m "Update Grass version to ${{ env.latest_grass_version }}" | |
fi | |
if [ "${{ steps.grass-node-version-check.outputs.grass_node_build }}" == "true" ]; then | |
git add "${{ env.GRASS_NODE_VERSION_FILE_PATH }}" | |
git commit -m "Update Grass-Node version to ${{ env.latest_grass_node_version }}" | |
fi | |
git push | |
- name: Create and push tags for new versions | |
if: steps.grass-version-check.outputs.grass_build == 'true' || steps.grass-node-version-check.outputs.grass_node_build == 'true' | |
run: | | |
git config --global user.name 'GitHub Actions' | |
git config --global user.email '[email protected]' | |
if [ "${{ steps.grass-version-check.outputs.grass_build }}" == "true" ]; then | |
git tag -a "grass_${{ env.latest_grass_version }}" -m "Update to Grass version ${{ env.latest_grass_version }}" | |
git push origin "grass_${{ env.latest_grass_version }}" | |
fi | |
if [ "${{ steps.grass-node-version-check.outputs.grass_node_build }}" == "true" ]; then | |
git tag -a "grass-node_${{ env.latest_grass_node_version }}" -m "Update to Grass-Node version ${{ env.latest_grass_node_version }}" | |
git push origin "grass-node_${{ env.latest_grass_node_version }}" | |
fi |