|
| 1 | +name: 🔄 Sync with upstream |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + outputs: |
| 6 | + missing_tags: |
| 7 | + description: The upstream tags that are missing locally |
| 8 | + value: ${{ jobs.sync_upstream.outputs.missing_tags }} |
| 9 | + snapd_tags: |
| 10 | + description: The new tags that we need to create |
| 11 | + value: ${{ jobs.sync_upstream.outputs.snapd_tags }} |
| 12 | + |
| 13 | +jobs: |
| 14 | + sync_upstream: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Install dependencies |
| 18 | + run: | |
| 19 | + sudo apt-get update |
| 20 | + sudo apt-get install -yyq jq |
| 21 | + - uses: actions/checkout@v3 |
| 22 | + - name: Configure GIT |
| 23 | + run: | |
| 24 | + git config user.email 'actions@github.com' |
| 25 | + git config user.name 'GitHub Actions' |
| 26 | + git remote add upstream https://github.com/microsoft/WSL2-Linux-Kernel.git |
| 27 | + - name: Sync from upstream |
| 28 | + run: | |
| 29 | + git fetch --tags origin |
| 30 | + git fetch --tags --prune --progress --no-recurse-submodules upstream +refs/heads/master*:refs/remotes/upstream/master* |
| 31 | + - name: Parse upstream tags |
| 32 | + id: parse_tags |
| 33 | + run: | |
| 34 | + set -x |
| 35 | +
|
| 36 | + REMOTE_TAGS="$(git show-ref --tags | awk '{print $2}' | cut -d/ -f3 | grep '^linux-msft-wsl-' || true)" |
| 37 | + ORIGIN_TAGS="$(git ls-remote --tags origin | grep -v '\^{}' | cut -f2 | cut -d/ -f3 | grep '^linux-msft-wsl-' || true)" |
| 38 | +
|
| 39 | + MISSING_TAGS="$(echo "$REMOTE_TAGS" | grep -v -F "$ORIGIN_TAGS" || true)" |
| 40 | +
|
| 41 | + FILTERED_UPSTREAM_TAGS=() |
| 42 | + FILTERED_SNAPD_TAGS=() |
| 43 | +
|
| 44 | + for UPSTREAM_TAG in $MISSING_TAGS; do |
| 45 | + # check that we have a non-empty string |
| 46 | + [ -n "$UPSTREAM_TAG" ] || continue |
| 47 | +
|
| 48 | + # check that the tag name matches the format we're expecting |
| 49 | + echo "$UPSTREAM_TAG" | grep -Eq '^linux-msft-wsl-([0-9]+\.[0-9]+).*$' || continue |
| 50 | +
|
| 51 | + # check that we haven't already built this tag |
| 52 | + SNAPD_TAG="${UPSTREAM_TAG/linux-msft-wsl-/linux-msft-snapd-}" |
| 53 | + [ -z "$(git tag -l "$SNAPD_TAG")" ] || continue |
| 54 | +
|
| 55 | + FILTERED_UPSTREAM_TAGS+=($UPSTREAM_TAG) |
| 56 | + FILTERED_SNAPD_TAGS+=($SNAPD_TAG) |
| 57 | + done |
| 58 | +
|
| 59 | + echo '::echo::on' |
| 60 | + if [ "${#FILTERED_UPSTREAM_TAGS[@]}" -gt 0 ]; then |
| 61 | + echo "::set-output name=missing_tags::$(jq --compact-output --null-input '$ARGS.positional' --args -- "${FILTERED_UPSTREAM_TAGS[@]}")" |
| 62 | + echo "::set-output name=snapd_tags::$(jq --compact-output --null-input '$ARGS.positional' --args -- "${FILTERED_SNAPD_TAGS[@]}")" |
| 63 | + else |
| 64 | + echo "::set-output name=missing_tags::" |
| 65 | + echo "::set-output name=snapd_tags::" |
| 66 | + fi |
| 67 | + - name: Rebase and push master; push tags |
| 68 | + run: | |
| 69 | + git rebase upstream/master |
| 70 | + git push --force origin master |
| 71 | + git push --force --tags origin |
| 72 | + outputs: |
| 73 | + missing_tags: ${{ steps.parse_tags.outputs.missing_tags }} |
| 74 | + snapd_tags: ${{ steps.parse_tags.outputs.snapd_tags }} |
0 commit comments