Bump docker/login-action from 3.6.0 to 3.7.0 #152
This file contains hidden or 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: "Version Increment" | |
| # | |
| #on: | |
| # # Run this action on any Pull Request raised against ARM | |
| # # pull_request: | |
| # # Ensure changes re-run the version script (i.e. title change) | |
| # types: [opened, edited, synchronize] | |
| # # Don't run on changes to the below paths | |
| # paths-ignore: | |
| # - 'arm_wiki/**' | |
| # - '.github/**' | |
| # | |
| # # Allows you to run this workflow manually from the Actions tab | |
| # workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| version: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Get branch name | |
| id: branch-name | |
| uses: tj-actions/branch-names@v9 | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| - name: Fetch main branch | |
| run: | | |
| git fetch origin main | |
| MAIN_VERSION=$(git show origin/main:VERSION) | |
| echo "MAIN_VERSION=$MAIN_VERSION" >> $GITHUB_ENV | |
| - name: Determine new version | |
| id: determine-version | |
| env: | |
| # Safely get title (avoid injection attacks) | |
| PR_TITLE: ${{ github.event.pull_request.title }} | |
| run: | | |
| # Set Title environment flag to false | |
| TITLE_FLAG="false" | |
| VERSION_TYPE="false" | |
| echo "PR Title: $PR_TITLE" | |
| if [[ "$PR_TITLE" == *"[FEATURE]"* ]]; then | |
| VERSION_TYPE="minor" | |
| echo "PR set to FEATURE updating minor version" | |
| TITLE_FLAG="true" | |
| elif [[ "$PR_TITLE" == *"[BUGFIX]"* ]]; then | |
| VERSION_TYPE="patch" | |
| echo "PR set to BUGFIX updating patch version" | |
| TITLE_FLAG="true" | |
| else | |
| echo "No version bump flag found in PR title. Exiting." | |
| echo "Edit your PR title to include either FEATURE or BUGFIX" | |
| fi | |
| # If Feature or Bugfix update the version | |
| if [[ "$TITLE_FLAG" == "true" ]]; then | |
| # Abort script if version file missing | |
| if [[ ! -f VERSION ]]; then | |
| echo "VERSION file not found! Aborting." | |
| exit 1 | |
| fi | |
| # Get branch version | |
| BRANCH_VERSION=$(cat VERSION) | |
| echo "Branch Version: $BRANCH_VERSION" | |
| # Get the main version and split into VERSION_PARTS | |
| IFS='.' read -r -a VERSION_PARTS <<< "$MAIN_VERSION" | |
| if [[ "$VERSION_TYPE" == "minor" ]]; then | |
| VERSION_PARTS[1]=$((VERSION_PARTS[1]+1)) | |
| VERSION_PARTS[2]=0 | |
| elif [[ "$VERSION_TYPE" == "patch" ]]; then | |
| VERSION_PARTS[2]=$((VERSION_PARTS[2]+1)) | |
| fi | |
| NEW_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.${VERSION_PARTS[2]}" | |
| echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV | |
| echo "New Version: " $NEW_VERSION | |
| fi | |
| # Set variables to global environment variables for later | |
| echo "TITLE_FLAG=$TITLE_FLAG" >> $GITHUB_ENV | |
| echo "PR_TITLE=$PR_TITLE" >> $GITHUB_ENV | |
| echo "VERSION_TYPE=$VERSION_TYPE" >> $GITHUB_ENV | |
| echo "BRANCH_VERSION=$BRANCH_VERSION" >> $GITHUB_ENV | |
| - name: Comment on PR with no spam | |
| uses: actions/github-script@v8 | |
| with: | |
| github-token: ${{ secrets.VERSION_BOT }} | |
| script: | | |
| // Retrieve variables from the environment | |
| const titleFlag = process.env.TITLE_FLAG; | |
| const prNumber = context.issue.number; | |
| const prTitle = process.env.PR_TITLE; | |
| const newVersion = process.env.NEW_VERSION; | |
| const currentVersion = process.env.MAIN_VERSION; | |
| const branchVersion = process.env.BRANCH_VERSION; | |
| const versionType = process.env.VERSION_TYPE; | |
| // Prepare the message based on the title flag | |
| let prBody; | |
| if (titleFlag === "false") { | |
| prBody = `ARM Version Bot\n **PR title:** ${prTitle}\n **No valid version flag found**. PR title must include either [FEATURE] or [BUGFIX] to auto-increment the version.\n **Please update the PR title** and re-run the workflow.`; | |
| } else { | |
| prBody = `ARM Version Bot:\n **PR title:** ${prTitle}\n **Current version:** ${currentVersion}\n **Required Version:** ${newVersion}\n **PR Version:** ${branchVersion}\n **Release version:** ${versionType}`; | |
| } | |
| // Get existing comments | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| per_page: 100 | |
| }); | |
| // Check for existing version bot comments | |
| const botComment = comments.find(comment => | |
| comment.user.type === 'Bot' && | |
| comment.body.includes('Version Bot') | |
| ); | |
| // Generate PR comment if not already there | |
| if (botComment) { | |
| // Check if comment aligns with expected output, otherwise update | |
| if (botComment.body !== prBody) { | |
| // Update the existing comment | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: botComment.id, | |
| body: prBody | |
| }); | |
| console.log('Updated existing Version Bot comment.'); | |
| } else { | |
| console.log('No comment update needed.'); | |
| } | |
| } else { | |
| // Creating new comment, no previous comments found | |
| console.log('Creating new comment'); | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| body: prBody | |
| }) | |
| } |