-
Notifications
You must be signed in to change notification settings - Fork 8
122 lines (109 loc) · 4.58 KB
/
release.yml
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
name: Create Release
run-name: Create `${{ inputs.version }}` release from `${{ github.ref_name }}` branch
on:
workflow_dispatch:
inputs:
version:
description: The version to tag and release
required: true
jobs:
release:
name: Create Release
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
token: ${{ secrets.REPO_DISPATCH_TOKEN }}
ref: 2.x
- name: Set variables for Docker images
run: |
oldhash=${{ hashFiles('Dockerfile', 'package.json', 'package-lock.json', 'scripts/*') }}
registry='ghcr.io'
imageprefix="${registry}/${GITHUB_REPOSITORY}/"
imagename='az-nodejs-ephemeral'
imagestem="${imageprefix}${imagename}:"
echo "AZ_DOCKER_REGISTRY=${registry}" >> ${GITHUB_ENV}
echo "AZ_OLD_HASH=${oldhash}" >> ${GITHUB_ENV}
echo "AZ_IMAGE_STEM=${imagestem}" >> ${GITHUB_ENV}
echo "AZ_BOOTSTRAP_SOURCE_DIR=/arizona-bootstrap-source" >> ${GITHUB_ENV}
echo "AZ_BOOTSTRAP_FROZEN_DIR=/azbuild/arizona-bootstrap" >> ${GITHUB_ENV}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Docker authentication
run: |
docker login "$AZ_DOCKER_REGISTRY" -u "$GITHUB_ACTOR" -p ${{ secrets.GITHUB_TOKEN }}
- name: Unconditionally rebuild and save the Docker image
run: |
workingtitle=$(docker build -q . )
tempname="old${AZ_OLD_HASH}"
docker run --name "$tempname" "$workingtitle" true
docker cp -a "${tempname}:${AZ_BOOTSTRAP_FROZEN_DIR}/." .
docker rm "$tempname"
lockhash=${{ hashFiles('Dockerfile', 'package.json', 'package-lock.json', 'scripts/*') }}
ephemeral="${AZ_IMAGE_STEM}${lockhash}"
docker tag "$workingtitle" "$ephemeral"
docker push "$ephemeral"
echo "AZ_EPHEMERAL_IMAGE=${ephemeral}" >> ${GITHUB_ENV}
- name: Build variables
run: |
echo "AZ_VERSION=${{ github.event.inputs.version }}" >> ${GITHUB_ENV}
- name: Update version
run: |
sudo touch config.yml
sudo find . -path "./.git" -prune -o -exec chown 1000:1000 {} \;
sudo chown 1000:1000 .
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git config --global user.name "${GITHUB_ACTOR}"
docker run --rm -e "AZ_RELEASE_VERSION=${AZ_VERSION}" -v $(pwd):"${AZ_BOOTSTRAP_SOURCE_DIR}" "$AZ_EPHEMERAL_IMAGE" create-release
git add dist package.json package-lock.json
git commit -m '${{ github.event.inputs.version }}'
git push
echo "RELEASE_SHA=$(git rev-parse HEAD)" >> ${GITHUB_ENV}
echo "BRANCH_NAME=${GITHUB_REF_NAME}" >> ${GITHUB_ENV}
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
commitish: "${{ env.RELEASE_SHA }}"
tag_name: "v${{ env.AZ_VERSION }}"
release_name: "v${{ env.AZ_VERSION }}"
draft: false
prerelease: false #${{ contains(env.AZ_VERSION, '-alpha') }}
- name: Save new SHA to file
run: |
echo "{\"sha\": \"$(git rev-parse HEAD)\"}" > ${{ runner.temp }}/variables.json
- name: Upload variables
uses: actions/upload-artifact@v3
with:
name: variables-json-artifact
path: ${{ runner.temp }}/variables.json
dispatch:
needs: release
strategy:
matrix:
repo:
- az-digital/arizona-bootstrap
- az-digital/arizona-bootstrap-packagist
- az-digital/digital.arizona.edu
runs-on: ubuntu-latest
steps:
- name: Download variables
uses: actions/download-artifact@v3
with:
name: variables-json-artifact
path: ${{ runner.temp }}
- name: Update environment variables
run: |
variablesfile=${{ runner.temp }}/variables.json
echo "RELEASE_SHA=$(cat ${variablesfile} | jq -r '.sha' )" >> ${GITHUB_ENV}
echo "BRANCH_NAME=${GITHUB_REF_NAME}" >> ${GITHUB_ENV}
- name: Notify dependencies
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.REPO_DISPATCH_TOKEN }}
repository: ${{ matrix.repo }}
event-type: az_bootstrap_release
client-payload: '{"version": "${{ github.event.inputs.version }}", "ref": "${{ env.RELEASE_SHA }}", "sha": "${{ env.RELEASE_SHA }}", "branch": "${{env.BRANCH_NAME}}"}'