diff --git a/.github/workflows/pr-to-update-choco.yml b/.github/workflows/pr-to-update-choco.yml new file mode 100644 index 0000000000..45052be356 --- /dev/null +++ b/.github/workflows/pr-to-update-choco.yml @@ -0,0 +1,106 @@ +name: PR for updating Chocolatey + +# This action will run after a tag starting with "v" is published +# on: +# push: +# tags: +# - 'v*' +# workflow_dispatch: +on: + push: + branches: + - automate-choco-workflow + +permissions: + contents: read + +jobs: + choco-update: + permissions: + contents: write # for Git to git push + pull-requests: write # for creating PRs + runs-on: ubuntu-latest + steps: + - name: Checkout Headlamp + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + with: + token: ${{ secrets.KINVOLK_REPOS_TOKEN }} + # we need the full history for the git tag command, so fetch all the branches + fetch-depth: 0 + - name: Configure Git + run: | + user=${{github.actor}} + if [ -z $user ]; then + user=vyncent-t + fi + git config --global user.name "$user" + git config --global user.email "$user@users.noreply.github.com" + # Set up Node.js environment, pay attention to the version + # Some features might not be available in older versions + - name: Create node.js environment + uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 + with: + node-version: '21' + # Install the app dependencies for the choco script + - name: Install app dependencies + run: | + cd $GITHUB_WORKSPACE/app + npm ci + # We set the latest tag as an environment variable before we use it in the next steps + # note that we have to echo the variable to the environment file to make it available in the next steps + - name: Set latest tag + run: | + echo "Setting latest tag" + latestTag=$(git tag --list --sort=version:refname 'v*' | tail -1) + # Remove the 'v' from the tag + latestTag=${latestTag#v} + echo "LATEST_HEADLAMP_TAG=$latestTag" >> $GITHUB_ENV + echo $latestTag + - name: Set hash and checksum + run: | + echo "Setting hash and checksum" + cd $GITHUB_WORKSPACE/app/windows/chocolatey + curl -O https://github.com/headlamp-k8s/headlamp/releases/download/v$LATEST_HEADLAMP_TAG/checksums.txt + ls checksums.txt + echo "Setting hash" + read -r hash win_file_name <<< $(grep win ./checksums.txt) + echo "WIN_FILE_NAME=$win_file_name" >> $GITHUB_ENV + echo "WIN_FILE_HASH=$hash" >> $GITHUB_ENV + # Run the choco script + - name: Create nuget package + run: | + echo "Running choco script" + echo "Repository: ${{ github.repository }}" + echo "Workspace: ${GITHUB_WORKSPACE}" + echo $GITHUB_WORKSPACE + pwd + echo "LATEST_HEADLAMP_TAG=$LATEST_HEADLAMP_TAG" + echo "WIN_FILE_HASH=$WIN_FILE_HASH" + echo "creating nuget pkgs" + cd $GITHUB_WORKSPACE/app/windows/chocolatey + ./choco-bump.sh $LATEST_HEADLAMP_TAG $WIN_FILE_HASH + echo "Script finished" + # REFACTOR FOR CUSTOM NUGET REPO LATER IF NEEDED + - name: Create PR branch and push + run: | + user=${{github.actor}} + if [ -z $user ]; then + user=vyncent-t + fi + echo "Creating PR branch" + echo "Repository: ${{ github.repository }}" + echo "Workspace: ${GITHUB_WORKSPACE}" + pwd + ls + echo echo "https://github.com/headlamp-k8s/headlamp/pull/new/WIP-choco-update-$LATEST_HEADLAMP_TAG" + git checkout -b "WIP-choco-update-$LATEST_HEADLAMP_TAG" + git add . + git commit -s -m "chocolatey: Bump Headlamp version to $LATEST_HEADLAMP_TAG" + git push origin "WIP-choco-update-$LATEST_HEADLAMP_TAG" + gh pr create \ + --title "chocolatey: Bump Headlamp version to $LATEST_HEADLAMP_TAG" \ + --base main \ + --assignee $user \ + --body "This PR updates the chocolatey package to the latest version of Headlamp" \ + env: + GITHUB_TOKEN: ${{ secrets.KINVOLK_REPOS_TOKEN }}