-
Notifications
You must be signed in to change notification settings - Fork 16
134 lines (114 loc) · 5.92 KB
/
release.yaml
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
123
124
125
126
127
128
129
130
131
132
133
134
# This workflow creates a github release using changeset, and publishes it as an npm package.
# It's triggered once a release PR (created by the pre-release workflow) gets merged to the `main` branch.
name: Release
on:
# Once the PR gets merged to `main`
pull_request:
branches:
- main
- 'releases/**'
types: [closed]
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
# Enable release process either with workflow dispatch or the automated PR process
release:
name: Release
if: |
((github.event.pull_request.merged == true) &&
startsWith(github.event.pull_request.title, 'chore(release)'))
runs-on: blacksmith-2vcpu-ubuntu-2204
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup tools
uses: ./.github/actions/setup-tools
with:
install-nodejs: 'true'
# Publishes a release in case the release isn't published
- name: Publish release
id: publish-release
uses: changesets/action@v1
with:
publish: npm run release
createGithubReleases: true
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# Prepare the variables that will be used across the different next steps
- name: Prepare cross-steps variables
run: |
export PACKAGE_NAME=$(jq -r '.name' 'package.json');
export PACKAGE_VERSION=v$(echo '${{ steps.publish-release.outputs.publishedPackages }}' | jq -r ".[] | select(.name == \"${PACKAGE_NAME}\") | .version")
export BASE_ARTIFACTS_DIR="./artifacts"
export ARTIFACT_NAME="interchain-token-service-assets-${PACKAGE_VERSION}"
export BASE_ARTIFACTS_VERSIONED_DIR="$(dirname ${BASE_ARTIFACTS_DIR})/${ARTIFACT_NAME}" # Regardless of the dir type, relative or absolute
# ex: @axelarnetwork/interchain-token-service
echo "PACKAGE_NAME=${PACKAGE_NAME}" >> $GITHUB_ENV
# ex: v2.1.0
echo "PACKAGE_VERSION=${PACKAGE_VERSION}" >> $GITHUB_ENV
# ex: ./artifacts
echo "BASE_ARTIFACTS_DIR=${BASE_ARTIFACTS_DIR}" >> $GITHUB_ENV
# ex: interchain-token-service-assets-v2.1.0
echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV
# ex: ./interchain-token-service-assets-v2.1.0
echo "BASE_ARTIFACTS_VERSIONED_DIR=${BASE_ARTIFACTS_VERSIONED_DIR}" >> $GITHUB_ENV
# Create `zip` and `tar` archive files for contracts ABIs
- name: Create `zip` and `tar` archive files for contracts ABIs
run: |
# Renaming to keep the dir structure in the archive matching the release version defined in `BASE_ARTIFACTS_VERSIONED_DIR`
mv ${{ env.BASE_ARTIFACTS_DIR }} ${{ env.BASE_ARTIFACTS_VERSIONED_DIR }}
find "${{ env.BASE_ARTIFACTS_VERSIONED_DIR }}/contracts" -type f -name "*.json" -print | zip ${{ env.ARTIFACT_NAME }}.zip -@
find "${{ env.BASE_ARTIFACTS_VERSIONED_DIR }}/contracts" -type f -name "*.json" -print | tar -czvf ${{ env.ARTIFACT_NAME }}.tar.gz -T -
# Generate SHA-256 Checksums
for file in ${{ env.ARTIFACT_NAME }}.tar.gz ${{ env.ARTIFACT_NAME }}.zip; do
sha256sum "$file" > "$file.sha256"
done
# Publishing contracts ABIs to `R2`
- name: Configure CF credentials
run: |
cd $HOME; mkdir ~/.aws; touch ~/.aws/credentials; touch ~/.aws/config
echo "[default]
aws_access_key_id = ${{ secrets.CF_BUCKET_ACCESS_KEY_ID }}
aws_secret_access_key = ${{ secrets.CF_BUCKET_SECRET_ACCESS_KEY }}" > ~/.aws/credentials
echo "[default]
region=auto
output=json" > ~/.aws/config
- name: Publish files to CF R2
env:
S3_BUCKET_NAME: ${{ vars.CF_BUCKET_NAME }}
ENDPOINT_URL: ${{ secrets.CF_ENDPOINT_URL }}
CF_BUCKET_ROOT_KEY: ${{ vars.CF_BUCKET_ROOT_KEY }}
run: |
export CF_CONTRACTS_BUCKET_ROOT_KEY="${CF_BUCKET_ROOT_KEY}/${{ env.PACKAGE_VERSION }}"
export JSON_FILES=$(find "${{ env.BASE_ARTIFACTS_VERSIONED_DIR }}/contracts" -type f -name "*.json")
for json_file in "${JSON_FILES}"; do
echo "Uploading configs: ${json_file}"
for file in ${json_file}; do
if [[ -f "$file" ]]; then
FILE_KEY=$(echo $file | sed "s|^${{ env.BASE_ARTIFACTS_VERSIONED_DIR }}/||")
echo "Uploading config: $CF_CONTRACTS_BUCKET_ROOT_KEY/$FILE_KEY"
aws s3api put-object --bucket $S3_BUCKET_NAME --key "$CF_CONTRACTS_BUCKET_ROOT_KEY/$FILE_KEY" --body "$file" --acl public-read --endpoint-url $ENDPOINT_URL
fi
done
done
# Upload the created archives to R2
export CF_ARCHIVES_BUCKET_ROOT_KEY="${CF_BUCKET_ROOT_KEY}/${{ env.PACKAGE_VERSION }}/archives"
for file in ${{ env.ARTIFACT_NAME }}.tar.gz ${{ env.ARTIFACT_NAME }}.zip; do
aws s3api put-object --bucket $S3_BUCKET_NAME --key "$CF_ARCHIVES_BUCKET_ROOT_KEY/$file" --body "$file" --acl public-read --endpoint-url $ENDPOINT_URL
aws s3api put-object --bucket $S3_BUCKET_NAME --key "$CF_ARCHIVES_BUCKET_ROOT_KEY/$file.sha256" --body "$file.sha256" --acl public-read --endpoint-url $ENDPOINT_URL
done
# Update the existing release and upload the zip and tar archives to the specific tag
- name: Create and Upload Release
uses: softprops/action-gh-release@c062e08bd532815e2082a85e87e3ef29c3e6d191 # v2.0.8
with:
tag_name: ${{ env.PACKAGE_VERSION }} # This uses the tag from the push
files: |
${{ env.ARTIFACT_NAME }}.tar.gz
${{ env.ARTIFACT_NAME }}.tar.gz.sha256
${{ env.ARTIFACT_NAME }}.zip
${{ env.ARTIFACT_NAME }}.zip.sha256
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}