summaryrefslogtreecommitdiff
path: root/.github/workflows/update-elixir-patches.yaml
blob: 4ce158502efee0278d7dc521f073e49164a87d9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: Update Elixir Patch Versions for Bazel Based Workflows
on:
  schedule:
  - cron: '0 3 * * *'
  workflow_dispatch:
jobs:
  update-toolchains:
    name: Update Elixir Versions
    runs-on: ubuntu-20.04
    strategy:
      max-parallel: 1
      fail-fast: false
      matrix:
        include:
        - elixir_version: "1.13"
          name: '1_13'
        - elixir_version: "1.14"
          name: '1_14'
    timeout-minutes: 10
    env:
      branch: bump-elixir-${{ matrix.elixir_version }}
    steps:
    - name: CHECKOUT REPOSITORY
      uses: actions/checkout@v3
    - name: FAIL IF THE PR ALREADY EXISTS
      id: check-for-branch
      run: |
        set +e
        if git ls-remote --exit-code --heads origin ${{ env.branch }}; then
          echo "Branch ${{ env.branch }} already exits"
          exit 1
        fi
    - name: DETERMINE LATEST PATCH & SHA
      id: fetch-version
      run: |
        TAG_NAME=$(curl -s GET https://api.github.com/repos/elixir-lang/elixir/tags?per_page=100 \
          | jq -r 'map(select(.name | contains("v${{ matrix.elixir_version }}"))) | first | .name')

        if [[ -z "${TAG_NAME}" ]]; then
          echo "Failed to determine latest TAG_NAME for v${{ matrix.elixir_version }}"
          exit 1
        fi

        ARCHIVE_URL="https://github.com/elixir-lang/elixir/archive/${TAG_NAME}.tar.gz"
        wget --continue --quiet --output-document="/tmp/elixir.tar.gz" "${ARCHIVE_URL}" && \
        SHA="$(shasum -a 256 "/tmp/elixir.tar.gz" | awk '{print $1}')"

        if [[ -z "${SHA}" ]]; then
          echo "Failed to determine SHA for ${TAG_NAME}"
          exit 1
        fi

        echo "VERSION=${TAG_NAME#v}" >> $GITHUB_OUTPUT
        echo "SHA=${SHA}" >> $GITHUB_OUTPUT
    - name: MODIFY VERSION FILE
      run: |
        sudo npm install --global --silent @bazel/buildozer

        OLD_SHA="$(cat MODULE.bazel | buildozer 'print sha256' -:${{ matrix.name }})"
        OLD_VERSION="$(cat MODULE.bazel | buildozer 'print version' -:${{ matrix.name }})"

        echo "$(cat MODULE.bazel | buildozer 'set sha256 "${{ steps.fetch-version.outputs.SHA }}"' -:${{ matrix.name }})" > MODULE.bazel
        echo "$(cat MODULE.bazel | buildozer 'set version "${{ steps.fetch-version.outputs.VERSION }}"' -:${{ matrix.name }})" > MODULE.bazel

        sed -i"_orig" "s/${OLD_SHA}/${{ steps.fetch-version.outputs.SHA }}/" WORKSPACE
        sed -i"_orig" "s/${OLD_VERSION}/${{ steps.fetch-version.outputs.VERSION }}/" WORKSPACE
        rm *_orig

        set -x
        git diff
    - name: CREATE PULL REQUEST
      uses: peter-evans/create-pull-request@v5.0.1
      with:
        token: ${{ secrets.REPO_SCOPED_TOKEN }}
        committer: GitHub <noreply@github.com>
        author: GitHub <noreply@github.com>
        title: Adopt elixir ${{ steps.fetch-version.outputs.VERSION }}
        body: >
           Automated changes created by
           ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
           using the [create-pull-request](https://github.com/peter-evans/create-pull-request)
           GitHub action in the ${{ github.workflow }} workflow.
        commit-message: |
          Adopt elixir ${{ steps.fetch-version.outputs.VERSION }}
        labels: |
          backport-v3.12.x
          backport-v3.11.x
          backport-v3.10.x
        branch: ${{ env.branch }}
        delete-branch: true