|
| 1 | +name: GitHub Jobs Post Merge |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths: |
| 8 | + - ".github/workflows/job_**" |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + id-token: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + get-file-names: |
| 17 | + name: Get Names of Files Changed |
| 18 | + runs-on: ubuntu-24.04 |
| 19 | + env: |
| 20 | + SAM_CLI_TELEMETRY: 0 |
| 21 | + defaults: |
| 22 | + run: |
| 23 | + shell: bash |
| 24 | + working-directory: . |
| 25 | + outputs: |
| 26 | + FILE_NAMES: ${{ steps.get-files.outputs.NAMES }} |
| 27 | + steps: |
| 28 | + - name: Checkout Repository |
| 29 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 30 | + with: |
| 31 | + submodules: true |
| 32 | + fetch-depth: 0 |
| 33 | + |
| 34 | +# This is ugly but can't get anything else to work |
| 35 | + - name: Get File Names |
| 36 | + id: get-files |
| 37 | + run: | |
| 38 | + files=$( git diff origin/main --name-only -- ./.github/workflows/job_** ) |
| 39 | +
|
| 40 | + JSON="[" |
| 41 | + for file in ${files[@]}; do |
| 42 | + echo $file |
| 43 | + JSONline="\"$file\"," |
| 44 | + if [[ "$JSON" != *"$JSONline"* ]]; then |
| 45 | + JSON="$JSON$JSONline" |
| 46 | + fi |
| 47 | + done |
| 48 | +
|
| 49 | + if [[ $JSON == *, ]]; then |
| 50 | + JSON="${JSON%?}" |
| 51 | + fi |
| 52 | + JSON="$JSON]" |
| 53 | +
|
| 54 | + echo $JSON |
| 55 | + echo "NAMES=$( echo "$JSON" )" >> $GITHUB_OUTPUT |
| 56 | +
|
| 57 | + create-tags: |
| 58 | + name: Validate Versions and Create Tags |
| 59 | + runs-on: ubuntu-24.04 |
| 60 | + needs: get-file-names |
| 61 | + strategy: |
| 62 | + matrix: |
| 63 | + file_name: ${{ fromJSON(needs.get-file-names.outputs.FILE_NAMES) }} |
| 64 | + env: |
| 65 | + SAM_CLI_TELEMETRY: 0 |
| 66 | + FILE_NAME: ${{ matrix.file_name }} |
| 67 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 68 | + defaults: |
| 69 | + run: |
| 70 | + shell: bash |
| 71 | + working-directory: jobs |
| 72 | + steps: |
| 73 | + - name: Checkout Repository |
| 74 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 75 | + with: |
| 76 | + submodules: true |
| 77 | + fetch-depth: 0 |
| 78 | + |
| 79 | + - name: Setup NodeJS |
| 80 | + uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 |
| 81 | + with: |
| 82 | + cache: npm |
| 83 | + cache-dependency-path: jobs/package-lock.json |
| 84 | + node-version-file: jobs/.nvmrc |
| 85 | + |
| 86 | + - name: Install Dependencies |
| 87 | + run: | |
| 88 | + npm clean-install |
| 89 | +
|
| 90 | + - name: Validate Job Name |
| 91 | + id: job-name |
| 92 | + run: | |
| 93 | + name=$( yq .description ../$FILE_NAME | jq .name | tr -d '"' ) |
| 94 | +
|
| 95 | + if [[ $FILE_NAME == ".github/workflows/job_$name" ]]; then |
| 96 | + echo "Error: Job name does not match file name." |
| 97 | + exit 1 |
| 98 | + fi |
| 99 | +
|
| 100 | + if [[ "$name" =~ ^[a-z0-9-]+$ ]]; then |
| 101 | + echo "Valid job name." |
| 102 | + echo "NAME=$name" >> $GITHUB_OUTPUT |
| 103 | + else |
| 104 | + echo "Error: Invalid job name." |
| 105 | + exit 1 |
| 106 | + fi |
| 107 | +
|
| 108 | + - name: Get Version |
| 109 | + id: get-version |
| 110 | + run: | |
| 111 | + version=$( yq .description ../$FILE_NAME | jq .version | tr -d '"' ) |
| 112 | + echo "VERSION=$version" >> $GITHUB_OUTPUT |
| 113 | +
|
| 114 | + - name: Validate Version |
| 115 | + run: | |
| 116 | + npm run validate-version $FILE_NAME |
| 117 | +
|
| 118 | + - name: Get Message |
| 119 | + id: get-message |
| 120 | + run: | |
| 121 | + message=$( yq .description ../$FILE_NAME | jq .message ) |
| 122 | + echo "MESSAGE=$message" >> $GITHUB_OUTPUT |
| 123 | +
|
| 124 | + - name: Create and Push Tag |
| 125 | + run: | |
| 126 | + job_name=${{ steps.job-name.outputs.NAME }} |
| 127 | + new_version=${{ steps.get-version.outputs.VERSION }} |
| 128 | + |
| 129 | + git tag $job_name/$new_version |
| 130 | + git push origin $job_name/$new_version |
| 131 | +
|
| 132 | + - name: Create GitHub Release |
| 133 | + run: | |
| 134 | + job_name=${{ steps.job-name.outputs.NAME }} |
| 135 | + message=${{ steps.get-message.outputs.MESSAGE }} |
| 136 | + new_version=${{ steps.get-version.outputs.VERSION }} |
| 137 | +
|
| 138 | + gh release create $job_name/$new_version --latest=false --notes "$message" |
0 commit comments